@ynhcj/xiaoyi-channel 0.0.199-beta → 0.0.199-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 +3 -8
- package/dist/index.js +146 -2
- package/dist/src/bot.js +77 -109
- package/dist/src/channel.js +83 -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.d.ts +1 -1
- package/dist/src/cspl/call_api.js +6 -10
- package/dist/src/cspl/config.d.ts +0 -1
- package/dist/src/cspl/config.js +68 -59
- package/dist/src/cspl/constants.d.ts +36 -1
- package/dist/src/cspl/constants.js +9 -0
- package/dist/src/cspl/sentinel_hook.js +33 -28
- package/dist/src/cspl/upload_file.js +5 -6
- package/dist/src/cspl/utils.d.ts +20 -9
- package/dist/src/cspl/utils.js +119 -75
- package/dist/src/formatter.js +72 -36
- package/dist/src/log-reporter/index.d.ts +1 -1
- package/dist/src/log-reporter/index.js +159 -35
- package/dist/src/log-reporter/openclaw-parser.d.ts +18 -0
- package/dist/src/log-reporter/openclaw-parser.js +94 -0
- package/dist/src/log-reporter/path-resolver.d.ts +5 -0
- package/dist/src/log-reporter/path-resolver.js +50 -0
- package/dist/src/log-reporter/reporter.d.ts +4 -4
- package/dist/src/log-reporter/reporter.js +52 -13
- package/dist/src/log-reporter/scanner.d.ts +7 -3
- package/dist/src/log-reporter/scanner.js +3 -7
- package/dist/src/log-reporter/types.d.ts +26 -27
- package/dist/src/log-reporter/uploader.d.ts +4 -3
- package/dist/src/log-reporter/uploader.js +32 -9
- package/dist/src/monitor.js +19 -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 +78 -16
- package/dist/src/reply-dispatcher.d.ts +3 -0
- package/dist/src/reply-dispatcher.js +178 -164
- package/dist/src/self-evolution-handler.js +2 -1
- package/dist/src/skill-retriever/config.js +2 -0
- package/dist/src/skill-retriever/hooks.js +1 -0
- package/dist/src/skill-retriever/tool-search.d.ts +3 -0
- package/dist/src/skill-retriever/tool-search.js +27 -11
- package/dist/src/skill-retriever/types.d.ts +1 -0
- package/dist/src/subagent-wait-state.d.ts +66 -0
- package/dist/src/subagent-wait-state.js +226 -0
- 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 +10 -5
- 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.js +1 -7
- 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/hmos-cli.d.ts +103 -0
- package/dist/src/tools/hmos-cli.js +562 -0
- 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/invoke.d.ts +88 -0
- package/dist/src/tools/invoke.js +1201 -0
- 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/logger.js +3 -14
- package/dist/src/websocket.d.ts +1 -1
- package/dist/src/websocket.js +22 -13
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
description: string;
|
|
5
|
-
configSchema: import("openclaw/plugin-sdk").OpenClawPluginConfigSchema;
|
|
6
|
-
register: NonNullable<import("openclaw/plugin-sdk/core").OpenClawPluginDefinition["register"]>;
|
|
7
|
-
} & Pick<import("openclaw/plugin-sdk/core").OpenClawPluginDefinition, "kind" | "reload" | "nodeHostCommands" | "securityAuditCollectors">;
|
|
8
|
-
export default _default;
|
|
1
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/core";
|
|
2
|
+
declare const pluginEntry: ReturnType<typeof definePluginEntry>;
|
|
3
|
+
export default pluginEntry;
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,14 @@ import { xiaoyiProvider } from "./src/provider.js";
|
|
|
3
3
|
import { xyPlugin } from "./src/channel.js";
|
|
4
4
|
import registerSentinelHook from "./src/cspl/sentinel_hook.js";
|
|
5
5
|
import { setXYRuntime } from "./src/runtime.js";
|
|
6
|
-
import { markCronToolCall, clearCronToolCall } from "./src/tools/session-manager.js";
|
|
6
|
+
import { markCronToolCall, clearCronToolCall, getCurrentSessionContext } from "./src/tools/session-manager.js";
|
|
7
|
+
import { configManager } from "./src/utils/config-manager.js";
|
|
8
|
+
import { setJobPushId } from "./src/utils/cron-push-map.js";
|
|
9
|
+
import { getAllPushIds } from "./src/utils/pushid-manager.js";
|
|
7
10
|
import { registerSelfEvolutionToolResultNudge } from "./src/self-evolution-tool-result-nudge.js";
|
|
8
11
|
import { createBeforePromptBuildHandler } from "./src/skill-retriever/hooks.js";
|
|
9
12
|
import { normalizeToolRetrieverConfig } from "./src/skill-retriever/config.js";
|
|
13
|
+
import { registerCLIHook } from "./src/tools/hmos-cli.js";
|
|
10
14
|
/**
|
|
11
15
|
* Register the cron detection hook.
|
|
12
16
|
*
|
|
@@ -25,8 +29,145 @@ function registerCronDetectionHook(api) {
|
|
|
25
29
|
if (event.toolCallId) {
|
|
26
30
|
clearCronToolCall(event.toolCallId);
|
|
27
31
|
}
|
|
32
|
+
// 捕获对话创建的 cron job:agent 调 cron(add) 后,从 result 拿 jobId,
|
|
33
|
+
// 配合当前会话的 pushId,写入 jobId↔pushId 映射,供 fire 时反查设备。
|
|
34
|
+
await captureCronAddMapping(event, ctx).catch((err) => {
|
|
35
|
+
// 捕获失败不影响工具结果
|
|
36
|
+
console.error("[xy] captureCronAddMapping failed:", err);
|
|
37
|
+
});
|
|
28
38
|
});
|
|
29
39
|
}
|
|
40
|
+
/** 从 cron add 工具结果中提取 jobId 并写入 pushId 映射。 */
|
|
41
|
+
async function captureCronAddMapping(event, ctx) {
|
|
42
|
+
// 两条创建路径都要捕获:
|
|
43
|
+
// 1) cron agent 工具:toolName==="cron", params.action==="add"
|
|
44
|
+
// 2) exec 跑 CLI:toolName==="exec", params.command 含 "cron add"
|
|
45
|
+
// (agent 实际用的是这条:openclaw cron add --name ... --cron ... --message ...)
|
|
46
|
+
const isCronAddTool = event.toolName === "cron" &&
|
|
47
|
+
(event.params?.action === "add" || event.params?.action === "create");
|
|
48
|
+
const isExecCronAdd = event.toolName === "exec" && isExecCronAddCommand(event.params?.command);
|
|
49
|
+
if (!isCronAddTool && !isExecCronAdd)
|
|
50
|
+
return;
|
|
51
|
+
console.log(`[CRONMAP] after_tool_call path=${event.toolName}, resultType=${typeof event.result}`);
|
|
52
|
+
const jobId = readJobIdFromResult(event.result);
|
|
53
|
+
if (!jobId) {
|
|
54
|
+
console.log(`[CRONMAP] skip: could not extract jobId. preview=${preview(event.result)}`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
console.log(`[CRONMAP] extracted jobId=${jobId}`);
|
|
58
|
+
const sessionCtx = getCurrentSessionContext();
|
|
59
|
+
const sessionId = sessionCtx?.sessionId;
|
|
60
|
+
if (!sessionId) {
|
|
61
|
+
console.log(`[CRONMAP] skip: no sessionId in ALS scope (ctxFound=${!!sessionCtx})`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const pushId = await resolvePushId(sessionId);
|
|
65
|
+
if (!pushId) {
|
|
66
|
+
console.log(`[CRONMAP] skip: no pushId available for sessionId=${sessionId} (no session match, no global, no file)`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
console.log(`[CRONMAP] writing map: jobId=${jobId}, sessionId=${sessionId}, pushId=${pushId.substring(0, 16)}...`);
|
|
70
|
+
await setJobPushId(jobId, {
|
|
71
|
+
pushId,
|
|
72
|
+
sessionId,
|
|
73
|
+
deviceType: sessionCtx?.deviceType,
|
|
74
|
+
source: event.toolName === "exec" ? "exec-cli" : "conversation",
|
|
75
|
+
});
|
|
76
|
+
console.log(`[CRONMAP] map written OK`);
|
|
77
|
+
}
|
|
78
|
+
/** 回退链取 pushId:当前会话 → 全局兜底 → 本地文件首个(保底)。 */
|
|
79
|
+
async function resolvePushId(sessionId) {
|
|
80
|
+
// 1. 同会话
|
|
81
|
+
const session = configManager.getPushId(sessionId);
|
|
82
|
+
if (session)
|
|
83
|
+
return session;
|
|
84
|
+
// 2. 全局(任何会话注册过的)
|
|
85
|
+
const global = configManager.getPushId();
|
|
86
|
+
if (global)
|
|
87
|
+
return global;
|
|
88
|
+
// 3. 文件兜底
|
|
89
|
+
try {
|
|
90
|
+
const all = await getAllPushIds();
|
|
91
|
+
if (all.length > 0)
|
|
92
|
+
return all[0];
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// ignore
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
/** 判断 exec 命令是否为 cron add(匹配 "openclaw cron add" 或裸 "cron add",排除 list/remove 等)。 */
|
|
100
|
+
function isExecCronAddCommand(command) {
|
|
101
|
+
if (typeof command !== "string")
|
|
102
|
+
return false;
|
|
103
|
+
return /\bcron\s+add\b/.test(command);
|
|
104
|
+
}
|
|
105
|
+
/** 取结果的短预览,用于诊断。 */
|
|
106
|
+
function preview(value) {
|
|
107
|
+
if (value == null)
|
|
108
|
+
return String(value);
|
|
109
|
+
const s = typeof value === "string" ? value : JSON.stringify(value);
|
|
110
|
+
return s.length > 200 ? s.slice(0, 200) + "…" : s;
|
|
111
|
+
}
|
|
112
|
+
/** 防御性地从 cron add 结果中取 job id。
|
|
113
|
+
* 覆盖:裸 job 对象、JSON 字符串、exec 输出文本、
|
|
114
|
+
* {content:[{text}]} / {stdout} / data/result/job 嵌套。 */
|
|
115
|
+
function readJobIdFromResult(result) {
|
|
116
|
+
if (!result)
|
|
117
|
+
return undefined;
|
|
118
|
+
// {content: [{type:"text", text: "..."}]} — exec 工具的输出信封
|
|
119
|
+
if (result && typeof result === "object") {
|
|
120
|
+
const contentArr = result.content;
|
|
121
|
+
if (Array.isArray(contentArr)) {
|
|
122
|
+
for (const item of contentArr) {
|
|
123
|
+
if (item && typeof item === "object") {
|
|
124
|
+
const text = item.text;
|
|
125
|
+
if (typeof text === "string" && text.trim()) {
|
|
126
|
+
const fromContent = readJobIdFromResult(text);
|
|
127
|
+
if (fromContent)
|
|
128
|
+
return fromContent;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// {stdout} — 备选 exec 输出信封
|
|
135
|
+
if (result && typeof result === "object") {
|
|
136
|
+
const stdout = result.stdout;
|
|
137
|
+
if (typeof stdout === "string" && stdout.trim()) {
|
|
138
|
+
const fromStdout = readJobIdFromResult(stdout);
|
|
139
|
+
if (fromStdout)
|
|
140
|
+
return fromStdout;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
let obj = result;
|
|
144
|
+
if (typeof result === "string") {
|
|
145
|
+
try {
|
|
146
|
+
obj = JSON.parse(result);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// 纯文本:可能含 stderr 前缀行 + JSON。用正则抓 "id":"..."。
|
|
150
|
+
const m = result.match(/"id"\s*:\s*"([^"]+)"/);
|
|
151
|
+
if (m)
|
|
152
|
+
return m[1];
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (obj && typeof obj === "object") {
|
|
157
|
+
const id = obj.id;
|
|
158
|
+
if (typeof id === "string" && id.trim())
|
|
159
|
+
return id.trim();
|
|
160
|
+
for (const k of ["data", "result", "job"]) {
|
|
161
|
+
const inner = obj[k];
|
|
162
|
+
if (inner && typeof inner === "object") {
|
|
163
|
+
const innerId = inner.id;
|
|
164
|
+
if (typeof innerId === "string" && innerId.trim())
|
|
165
|
+
return innerId.trim();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
30
171
|
function registerFullHooks(api) {
|
|
31
172
|
// SKILL RETRIEVER HOOK: before_prompt_build hook
|
|
32
173
|
const pluginConfig = api.pluginConfig || {};
|
|
@@ -41,7 +182,7 @@ function registerFullHooks(api) {
|
|
|
41
182
|
api.on("before_prompt_build", beforePromptBuildHandler);
|
|
42
183
|
registerSelfEvolutionToolResultNudge(api);
|
|
43
184
|
}
|
|
44
|
-
|
|
185
|
+
const pluginEntry = definePluginEntry({
|
|
45
186
|
id: "xiaoyi-channel",
|
|
46
187
|
name: "Xiaoyi Channel",
|
|
47
188
|
description: "Xiaoyi channel plugin - Xiaoyi A2A protocol integration",
|
|
@@ -68,6 +209,9 @@ export default definePluginEntry({
|
|
|
68
209
|
registerSentinelHook(api);
|
|
69
210
|
// Cron detection hook: marks toolCallIds from cron sessions
|
|
70
211
|
registerCronDetectionHook(api);
|
|
212
|
+
// CLI exec hook: intercepts built-in exec for HarmonyOS CLI skill tools
|
|
213
|
+
registerCLIHook(api);
|
|
71
214
|
}
|
|
72
215
|
},
|
|
73
216
|
});
|
|
217
|
+
export default pluginEntry;
|
package/dist/src/bot.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { resolveRuntimeConversationBindingRoute } from "openclaw/plugin-sdk/conversation-runtime";
|
|
1
2
|
import { updateSessionStoreEntry, updateSessionStore, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
|
|
2
3
|
import { getXYRuntime } from "./runtime.js";
|
|
3
4
|
import { createXYReplyDispatcher } from "./reply-dispatcher.js";
|
|
4
|
-
import { parseA2AMessage, extractTextFromParts, extractFileParts, extractPushId, extractDeviceType, extractModelName, extractTriggerData, extractRunCrossTaskContext } from "./parser.js";
|
|
5
|
+
import { parseA2AMessage, extractTextFromParts, extractFileParts, extractPushId, extractDeviceType, extractAppVer, extractSdkApiVersion, extractModelName, extractTriggerData, extractRunCrossTaskContext } from "./parser.js";
|
|
5
6
|
import { downloadFilesFromParts } from "./file-download.js";
|
|
6
7
|
import { resolveXYConfig } from "./config.js";
|
|
7
8
|
import { sendStatusUpdate, sendClearContextResponse, sendTasksCancelResponse, sendA2AResponse } from "./formatter.js";
|
|
8
9
|
import { appendSelfEvolutionKeywordNudge, shouldNudgeForSelfEvolutionKeyword, } from "./self-evolution-keyword.js";
|
|
9
|
-
import {
|
|
10
|
+
import { queueAgentHarnessMessage } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
11
|
+
import { runWithSessionContext } from "./tools/session-manager.js";
|
|
10
12
|
import { configManager } from "./utils/config-manager.js";
|
|
11
13
|
import { addPushId } from "./utils/pushid-manager.js";
|
|
12
14
|
import { getPushDataById } from "./utils/pushdata-manager.js";
|
|
@@ -113,6 +115,13 @@ export async function handleXYMessage(params) {
|
|
|
113
115
|
// Steer injections skip taskId registration to avoid overwriting the active taskId
|
|
114
116
|
if (!skipReg) {
|
|
115
117
|
registerTaskId(parsed.sessionId, parsed.taskId, parsed.messageId);
|
|
118
|
+
// 🔑 steer 场景:同步更新活跃 dispatcher 的 fallback taskId/messageId
|
|
119
|
+
if (isUpdate) {
|
|
120
|
+
const updater = dispatcherUpdaters.get(parsed.sessionId);
|
|
121
|
+
if (updater) {
|
|
122
|
+
updater(parsed.taskId, parsed.messageId);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
116
125
|
// Extract and update push_id if present
|
|
117
126
|
const pushId = extractPushId(parsed.parts);
|
|
118
127
|
if (pushId) {
|
|
@@ -139,6 +148,15 @@ export async function handleXYMessage(params) {
|
|
|
139
148
|
if (deviceType) {
|
|
140
149
|
log.log(`[BOT] Extracted deviceType: ${deviceType}`);
|
|
141
150
|
}
|
|
151
|
+
// Extract app_ver and sdk_api_version if present
|
|
152
|
+
const appVer = extractAppVer(parsed.parts);
|
|
153
|
+
if (appVer) {
|
|
154
|
+
log.log(`[BOT] Extracted app_ver: ${appVer}`);
|
|
155
|
+
}
|
|
156
|
+
const sdkApiVersion = extractSdkApiVersion(parsed.parts);
|
|
157
|
+
if (sdkApiVersion) {
|
|
158
|
+
log.log(`[BOT] Extracted sdk_api_version: ${sdkApiVersion}`);
|
|
159
|
+
}
|
|
142
160
|
// Extract modelName if present (used by provider.ts to override model.id)
|
|
143
161
|
const modelName = extractModelName(parsed.parts);
|
|
144
162
|
if (modelName) {
|
|
@@ -160,19 +178,23 @@ export async function handleXYMessage(params) {
|
|
|
160
178
|
},
|
|
161
179
|
});
|
|
162
180
|
log.log(`[BOT] Resolved route, sessionKey=${route.sessionKey}`);
|
|
163
|
-
//
|
|
181
|
+
// Check for ACP runtime binding on this A2A conversation
|
|
182
|
+
const runtimeRoute = resolveRuntimeConversationBindingRoute({
|
|
183
|
+
route,
|
|
184
|
+
channel: "xiaoyi-channel",
|
|
185
|
+
accountId,
|
|
186
|
+
conversationId: parsed.sessionId,
|
|
187
|
+
});
|
|
188
|
+
route = runtimeRoute.route;
|
|
189
|
+
if (runtimeRoute.bindingRecord) {
|
|
190
|
+
log.log(runtimeRoute.boundSessionKey
|
|
191
|
+
? `[BOT] routed via bound conversation ${parsed.sessionId} -> ${runtimeRoute.boundSessionKey}`
|
|
192
|
+
: `[BOT] plugin-bound conversation ${parsed.sessionId}`);
|
|
193
|
+
}
|
|
194
|
+
// ALS only: no registerSession. The sessionContext built below is handed
|
|
195
|
+
// to runWithSessionContext() inside withReplyDispatcher.run, which is the
|
|
196
|
+
// single wrap point for the whole agent turn.
|
|
164
197
|
if (!skipReg) {
|
|
165
|
-
registerSession(route.sessionKey, {
|
|
166
|
-
config,
|
|
167
|
-
sessionId: parsed.sessionId,
|
|
168
|
-
distributionSessionId,
|
|
169
|
-
taskId: parsed.taskId,
|
|
170
|
-
messageId: parsed.messageId,
|
|
171
|
-
agentId: route.accountId,
|
|
172
|
-
deviceType,
|
|
173
|
-
modelName,
|
|
174
|
-
runCrossTaskContext: runCrossTaskContext ?? undefined,
|
|
175
|
-
});
|
|
176
198
|
// 🔑 Sync A2A modelName to OpenClaw session store so that session_status
|
|
177
199
|
// reports the correct model. Without this, session_status returns the
|
|
178
200
|
// configured default model instead of the A2A-specified one.
|
|
@@ -343,7 +365,18 @@ export async function handleXYMessage(params) {
|
|
|
343
365
|
const steerState = { steered: false };
|
|
344
366
|
// 🔑 创建dispatcher
|
|
345
367
|
log.log(`[BOT-DISPATCHER] Creating reply dispatcher`);
|
|
346
|
-
|
|
368
|
+
// Cleanup: 必须在 onIdle 内部执行(参见 reply-dispatcher.ts 中 onIdleComplete 的注释)
|
|
369
|
+
let cleaned = false;
|
|
370
|
+
const cleanup = () => {
|
|
371
|
+
if (cleaned)
|
|
372
|
+
return;
|
|
373
|
+
cleaned = true;
|
|
374
|
+
log.log(`[BOT] Cleanup started`);
|
|
375
|
+
streamingSignals.delete(parsed.sessionId);
|
|
376
|
+
decrementTaskIdRef(parsed.sessionId);
|
|
377
|
+
log.log(`[BOT] Cleanup completed`);
|
|
378
|
+
};
|
|
379
|
+
const { dispatcher, replyOptions, markDispatchIdle, startStatusInterval, updateFallbackTaskId } = createXYReplyDispatcher({
|
|
347
380
|
cfg,
|
|
348
381
|
runtime,
|
|
349
382
|
sessionId: parsed.sessionId,
|
|
@@ -351,7 +384,10 @@ export async function handleXYMessage(params) {
|
|
|
351
384
|
messageId: parsed.messageId,
|
|
352
385
|
accountId: route.accountId,
|
|
353
386
|
steerState,
|
|
387
|
+
onIdleComplete: cleanup,
|
|
354
388
|
});
|
|
389
|
+
// 🔑 注册 dispatcher 的 fallback taskId 更新函数,供 steer 路径调用
|
|
390
|
+
dispatcherUpdaters.set(parsed.sessionId, updateFallbackTaskId);
|
|
355
391
|
// Steer injections don't need status intervals
|
|
356
392
|
if (!skipReg) {
|
|
357
393
|
startStatusInterval();
|
|
@@ -365,6 +401,8 @@ export async function handleXYMessage(params) {
|
|
|
365
401
|
messageId: parsed.messageId,
|
|
366
402
|
agentId: route.accountId,
|
|
367
403
|
deviceType,
|
|
404
|
+
appVer: appVer ?? undefined,
|
|
405
|
+
sdkApiVersion: sdkApiVersion ?? undefined,
|
|
368
406
|
modelName,
|
|
369
407
|
runCrossTaskContext: runCrossTaskContext ?? undefined,
|
|
370
408
|
};
|
|
@@ -373,15 +411,14 @@ export async function handleXYMessage(params) {
|
|
|
373
411
|
dispatcher,
|
|
374
412
|
onSettled: () => {
|
|
375
413
|
log.log(`[BOT] onSettled, steered=${steerState.steered}`);
|
|
376
|
-
// 🔑 When steered, skip
|
|
414
|
+
// 🔑 When steered, skip cleanup — the first message's dispatcher is still running
|
|
377
415
|
if (steerState.steered) {
|
|
378
416
|
log.log(`[BOT] Steered dispatch settled, skipping cleanup`);
|
|
379
417
|
return;
|
|
380
418
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
log.log(`[BOT] Cleanup completed`);
|
|
419
|
+
// cleanup 已由 onIdleComplete 在 onIdle 的 finally 中执行。
|
|
420
|
+
// onSettled 不做任何清理(直接在这里清理会发生 race condition)。
|
|
421
|
+
dispatcherUpdaters.delete(parsed.sessionId);
|
|
385
422
|
},
|
|
386
423
|
run: () => {
|
|
387
424
|
// 🔐 Use AsyncLocalStorage to provide session context to tools.
|
|
@@ -390,6 +427,7 @@ export async function handleXYMessage(params) {
|
|
|
390
427
|
// signal init complete to release the global dispatch gate
|
|
391
428
|
// for the next session.
|
|
392
429
|
const dispatchPromise = runWithSessionContext(sessionContext, async () => {
|
|
430
|
+
log.log(`[ALS-PROOF] bot entered dispatch scope sessionId=${sessionContext.sessionId} taskId=${sessionContext.taskId} isSteer=false`);
|
|
393
431
|
log.log(`[BOT-DISPATCH] dispatchReplyFromConfig starting, body.length=${ctxPayload.Body?.length ?? 0}`);
|
|
394
432
|
try {
|
|
395
433
|
const result = await core.channel.reply.dispatchReplyFromConfig({
|
|
@@ -422,7 +460,7 @@ export async function handleXYMessage(params) {
|
|
|
422
460
|
errLog.error("Failed to handle XY message:", err);
|
|
423
461
|
runtime.error?.(`xy: Failed to handle message: ${String(err)}`);
|
|
424
462
|
errLog.log(`[BOT] Error occurred, attempting cleanup`);
|
|
425
|
-
// 🔑 错误时也要清理taskId
|
|
463
|
+
// 🔑 错误时也要清理taskId(session 走 ALS,作用域退出自动清理)
|
|
426
464
|
try {
|
|
427
465
|
const params = message.params;
|
|
428
466
|
const sessionId = params?.sessionId;
|
|
@@ -430,18 +468,6 @@ export async function handleXYMessage(params) {
|
|
|
430
468
|
errLog.log(`[BOT] Cleaning up after error`);
|
|
431
469
|
// 清理 taskId
|
|
432
470
|
decrementTaskIdRef(sessionId);
|
|
433
|
-
// 清理 session
|
|
434
|
-
const core = getXYRuntime();
|
|
435
|
-
const route = core.channel.routing.resolveAgentRoute({
|
|
436
|
-
cfg,
|
|
437
|
-
channel: "xiaoyi-channel",
|
|
438
|
-
accountId,
|
|
439
|
-
peer: {
|
|
440
|
-
kind: "direct",
|
|
441
|
-
id: sessionId,
|
|
442
|
-
},
|
|
443
|
-
});
|
|
444
|
-
unregisterSession(route.sessionKey);
|
|
445
471
|
errLog.log(`[BOT] Cleanup completed after error`);
|
|
446
472
|
}
|
|
447
473
|
}
|
|
@@ -476,8 +502,11 @@ if (!_g.__xyStreamingSignals)
|
|
|
476
502
|
_g.__xyStreamingSignals = new Map();
|
|
477
503
|
if (!_g.__xySteerQueues)
|
|
478
504
|
_g.__xySteerQueues = new Map();
|
|
505
|
+
if (!_g.__xyDispatcherUpdaters)
|
|
506
|
+
_g.__xyDispatcherUpdaters = new Map();
|
|
479
507
|
const streamingSignals = _g.__xyStreamingSignals;
|
|
480
508
|
const steerQueues = _g.__xySteerQueues;
|
|
509
|
+
const dispatcherUpdaters = _g.__xyDispatcherUpdaters;
|
|
481
510
|
/**
|
|
482
511
|
* 由 provider.ts 在 wrapStreamFn 调用时触发。
|
|
483
512
|
* 这是模型 API 被调用的精确时刻,此时 isStreaming 一定为 true。
|
|
@@ -524,7 +553,7 @@ function enqueueSteer(params) {
|
|
|
524
553
|
return next;
|
|
525
554
|
}
|
|
526
555
|
async function dispatchSteerWhenReady(params) {
|
|
527
|
-
const { sessionId,
|
|
556
|
+
const { sessionId, steerText } = params;
|
|
528
557
|
const log = logger.withContext(sessionId, params.parsed.taskId);
|
|
529
558
|
// 1. 等待第一条消息开始 streaming
|
|
530
559
|
// signal 可能尚未创建(第一条消息还在文件下载等耗时操作中),
|
|
@@ -550,7 +579,7 @@ async function dispatchSteerWhenReady(params) {
|
|
|
550
579
|
}
|
|
551
580
|
else {
|
|
552
581
|
// 轮询超时且 hasActiveTask 仍为 true——说明第一条消息可能卡在异常路径,
|
|
553
|
-
// 没有创建 signal
|
|
582
|
+
// 没有创建 signal。此时放弃,避免并发碰撞。
|
|
554
583
|
log.log(`[STEER-QUEUE] Signal never appeared after polling, skip steer to avoid collision`);
|
|
555
584
|
return;
|
|
556
585
|
}
|
|
@@ -559,83 +588,22 @@ async function dispatchSteerWhenReady(params) {
|
|
|
559
588
|
log.log(`[STEER-QUEUE] First message completed, skip steer`);
|
|
560
589
|
return;
|
|
561
590
|
}
|
|
562
|
-
// 3.
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
// 如果有文件附件,把路径拼到 steer 文本末尾,让模型通过工具读取
|
|
591
|
+
// 3. 直接注入到活跃的 Pi run 中,不创建独立 dispatcher。
|
|
592
|
+
// 模型回复通过第一条消息的 dispatcher 的 onPartialReply 流式发出,
|
|
593
|
+
// 使用 registerTaskId + updateFallbackTaskId 已同步的最新 taskId。
|
|
566
594
|
const mediaPaths = params.mediaPayload?.MediaPaths;
|
|
567
595
|
const fileHint = mediaPaths && mediaPaths.length > 0
|
|
568
596
|
? `\n【用户上传附件】:${JSON.stringify(mediaPaths)}`
|
|
569
597
|
: "";
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
channel: "xiaoyi-channel",
|
|
575
|
-
from: speaker,
|
|
576
|
-
timestamp: new Date(),
|
|
577
|
-
envelope: envelopeOptions,
|
|
578
|
-
body: messageBody,
|
|
598
|
+
const steerMessage = `${steerText}${fileHint}`;
|
|
599
|
+
log.log(`[STEER-QUEUE] Injecting steer message directly into active run`);
|
|
600
|
+
const injected = queueAgentHarnessMessage(sessionId, steerMessage, {
|
|
601
|
+
steeringMode: "all",
|
|
579
602
|
});
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
SessionKey: params.route.sessionKey,
|
|
587
|
-
AccountId: params.route.accountId,
|
|
588
|
-
ChatType: "direct",
|
|
589
|
-
GroupSubject: undefined,
|
|
590
|
-
SenderName: sessionId,
|
|
591
|
-
SenderId: sessionId,
|
|
592
|
-
Provider: "xiaoyi-channel",
|
|
593
|
-
Surface: "xiaoyi-channel",
|
|
594
|
-
MessageSid: `xiaoyi_${params.parsed.taskId}_${params.deviceType}`,
|
|
595
|
-
Timestamp: Date.now(),
|
|
596
|
-
WasMentioned: false,
|
|
597
|
-
CommandAuthorized: true,
|
|
598
|
-
OriginatingChannel: "xiaoyi-channel",
|
|
599
|
-
OriginatingTo: sessionId,
|
|
600
|
-
ReplyToBody: undefined,
|
|
601
|
-
...params.mediaPayload,
|
|
602
|
-
});
|
|
603
|
-
const steerState = { steered: true };
|
|
604
|
-
const { dispatcher, replyOptions } = createXYReplyDispatcher({
|
|
605
|
-
cfg: params.cfg,
|
|
606
|
-
runtime: params.runtime,
|
|
607
|
-
sessionId,
|
|
608
|
-
taskId: params.parsed.taskId,
|
|
609
|
-
messageId: params.parsed.messageId,
|
|
610
|
-
accountId: params.route.accountId,
|
|
611
|
-
steerState,
|
|
612
|
-
});
|
|
613
|
-
const sessionContext = {
|
|
614
|
-
config: resolveXYConfig(params.cfg),
|
|
615
|
-
sessionId,
|
|
616
|
-
taskId: params.parsed.taskId,
|
|
617
|
-
messageId: params.parsed.messageId,
|
|
618
|
-
agentId: params.route.accountId,
|
|
619
|
-
deviceType: params.deviceType,
|
|
620
|
-
};
|
|
621
|
-
log.log(`[STEER-QUEUE] Dispatching steer`);
|
|
622
|
-
await core.channel.reply.withReplyDispatcher({
|
|
623
|
-
dispatcher,
|
|
624
|
-
onSettled: () => {
|
|
625
|
-
log.log(`[STEER-QUEUE] Steer dispatch settled`);
|
|
626
|
-
},
|
|
627
|
-
run: () => {
|
|
628
|
-
return runWithSessionContext(sessionContext, async () => {
|
|
629
|
-
const result = await core.channel.reply.dispatchReplyFromConfig({
|
|
630
|
-
ctx: ctxPayload,
|
|
631
|
-
cfg: params.cfg,
|
|
632
|
-
dispatcher,
|
|
633
|
-
replyOptions,
|
|
634
|
-
});
|
|
635
|
-
log.log(`[STEER-QUEUE] dispatch result: ${JSON.stringify(result)}`);
|
|
636
|
-
return result;
|
|
637
|
-
});
|
|
638
|
-
},
|
|
639
|
-
});
|
|
640
|
-
log.log(`[STEER-QUEUE] Steer dispatch completed`);
|
|
603
|
+
if (injected) {
|
|
604
|
+
log.log(`[STEER-QUEUE] Steer message injected successfully`);
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
log.log(`[STEER-QUEUE] Steer injection failed — run may not be accepting messages`);
|
|
608
|
+
}
|
|
641
609
|
}
|