@ynhcj/xiaoyi-channel 0.0.205-beta → 0.0.205-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 +80 -1
- package/dist/src/bot.d.ts +0 -5
- package/dist/src/bot.js +84 -225
- package/dist/src/channel.js +21 -6
- package/dist/src/cspl/call_api.d.ts +1 -1
- package/dist/src/cspl/call_api.js +10 -12
- 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 +26 -22
- 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/log-reporter/index.d.ts +1 -1
- package/dist/src/log-reporter/index.js +164 -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 +7 -9
- package/dist/src/provider.js +2 -7
- package/dist/src/reply-dispatcher.js +10 -3
- package/dist/src/skill-retriever/config.js +2 -0
- package/dist/src/skill-retriever/hooks.js +4 -3
- 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/steer-queue.d.ts +1 -0
- package/dist/src/steer-queue.js +9 -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 +2 -0
- package/dist/src/task-manager.js +15 -4
- package/dist/src/tools/device-tool-map.js +0 -6
- package/dist/src/tools/hmos-cli.d.ts +109 -0
- package/dist/src/tools/hmos-cli.js +558 -0
- package/dist/src/tools/invoke.d.ts +88 -0
- package/dist/src/tools/invoke.js +1209 -0
- package/dist/src/utils/skills-logger.d.ts +5 -0
- package/dist/src/utils/skills-logger.js +76 -0
- package/dist/src/websocket.js +11 -0
- package/package.json +1 -1
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
|
@@ -10,6 +10,45 @@ import { getAllPushIds } from "./src/utils/pushid-manager.js";
|
|
|
10
10
|
import { registerSelfEvolutionToolResultNudge } from "./src/self-evolution-tool-result-nudge.js";
|
|
11
11
|
import { createBeforePromptBuildHandler } from "./src/skill-retriever/hooks.js";
|
|
12
12
|
import { normalizeToolRetrieverConfig } from "./src/skill-retriever/config.js";
|
|
13
|
+
import { registerCLIHook } from "./src/tools/hmos-cli.js";
|
|
14
|
+
import { writeSkillUsage } from "./src/utils/skills-logger.js";
|
|
15
|
+
import { getSteerQueue } from "./src/steer-queue.js";
|
|
16
|
+
/**
|
|
17
|
+
* Parse a file path string to detect if it refers to a SKILL.md file within
|
|
18
|
+
* a skills directory. Returns the skill name (parent directory) if so.
|
|
19
|
+
*
|
|
20
|
+
* Matches paths like:
|
|
21
|
+
* ~/.openclaw/workspace/skills/my-skill/SKILL.md
|
|
22
|
+
* /home/user/core_skills/my-skill/SKILL.md
|
|
23
|
+
* skills/my-skill/SKILL.md
|
|
24
|
+
*/
|
|
25
|
+
function extractSkillNameFromPath(filePath) {
|
|
26
|
+
if (typeof filePath !== "string" || !filePath)
|
|
27
|
+
return null;
|
|
28
|
+
// Normalize common path prefixes
|
|
29
|
+
const normalized = filePath.replace(/^~\//, "/home/").replace(/\\/g, "/");
|
|
30
|
+
// Match: .../skills/<skillName>/SKILL.md or .../skills/<skillName>/...
|
|
31
|
+
// Also match: .../core_skills/<skillName>/SKILL.md
|
|
32
|
+
const match = normalized.match(/\/(?:core_)?skills\/([^/]+)\/SKILL\.md$/i);
|
|
33
|
+
return match ? match[1] : null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Register the skills diagnostic event listener via after_tool_call hook.
|
|
37
|
+
*
|
|
38
|
+
* When openclaw fires a `skill.used` diagnostic event, the skill's SKILL.md
|
|
39
|
+
* is typically read by the model first. We detect SKILL.md reads through
|
|
40
|
+
* the `after_tool_call` hook and write the skill name to the skills log.
|
|
41
|
+
*/
|
|
42
|
+
function registerSkillsDiagnosticHook(api) {
|
|
43
|
+
api.on("after_tool_call", async (event, _ctx) => {
|
|
44
|
+
if (event.toolName !== "read")
|
|
45
|
+
return;
|
|
46
|
+
const skillName = extractSkillNameFromPath(event.params?.path);
|
|
47
|
+
if (skillName) {
|
|
48
|
+
writeSkillUsage(skillName);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
13
52
|
/**
|
|
14
53
|
* Register the cron detection hook.
|
|
15
54
|
*
|
|
@@ -180,8 +219,43 @@ function registerFullHooks(api) {
|
|
|
180
219
|
const beforePromptBuildHandler = createBeforePromptBuildHandler(skillRetrieverConfig);
|
|
181
220
|
api.on("before_prompt_build", beforePromptBuildHandler);
|
|
182
221
|
registerSelfEvolutionToolResultNudge(api);
|
|
222
|
+
// STEER INJECTION HOOK: reads pending steer messages queued by bot.ts
|
|
223
|
+
// and injects them as appendContext on the next agent turn.
|
|
224
|
+
// This bypasses dispatchReplyFromConfig's admitReplyTurn blocking.
|
|
225
|
+
//
|
|
226
|
+
// appendContext places the steer after the current prompt context (which
|
|
227
|
+
// includes the original user query + tool results), so the model sees:
|
|
228
|
+
// [original context]\n\n用户追加诉求:<steer text>
|
|
229
|
+
//
|
|
230
|
+
// Key is deleted BEFORE splice to avoid a race: if bot.ts pushes a new
|
|
231
|
+
// message between splice and delete, it would be lost when delete removes
|
|
232
|
+
// the (now-repopulated) entry. With delete-first, bot.ts always creates a
|
|
233
|
+
// fresh entry for new messages.
|
|
234
|
+
let hookFireCount = 0;
|
|
235
|
+
api.on("agent_turn_prepare", async (_event, ctx) => {
|
|
236
|
+
hookFireCount++;
|
|
237
|
+
// Use ctx.sessionId (A2A session UUID) as the queue lookup key.
|
|
238
|
+
// bot.ts writes with parsed.sessionId — both refer to the same A2A UUID.
|
|
239
|
+
const sessionId = ctx.sessionId;
|
|
240
|
+
if (!sessionId)
|
|
241
|
+
return;
|
|
242
|
+
const queue = getSteerQueue();
|
|
243
|
+
const pending = queue.get(sessionId);
|
|
244
|
+
// Diagnostic: log every N-th hook fire and whenever queue has entries
|
|
245
|
+
const queueKeys = Array.from(queue.keys());
|
|
246
|
+
if (hookFireCount <= 3 || queueKeys.length > 0 || (pending && pending.length > 0)) {
|
|
247
|
+
console.log(`[STEER-HOOK-DIAG] fireCount=${hookFireCount} sessionId=${sessionId} ` +
|
|
248
|
+
`sessionKey=${ctx.sessionKey} queueKeys=${JSON.stringify(queueKeys)} pendingLen=${pending?.length ?? 0}`);
|
|
249
|
+
}
|
|
250
|
+
if (!pending || pending.length === 0)
|
|
251
|
+
return;
|
|
252
|
+
queue.delete(sessionId); // delete first to prevent race
|
|
253
|
+
const text = pending.splice(0).join("\n\n");
|
|
254
|
+
console.log(`[STEER-HOOK] Injecting steer: sessionId=${sessionId} textLen=${text.length}`);
|
|
255
|
+
return { appendContext: `\n用户追加诉求:${text}` };
|
|
256
|
+
});
|
|
183
257
|
}
|
|
184
|
-
|
|
258
|
+
const pluginEntry = definePluginEntry({
|
|
185
259
|
id: "xiaoyi-channel",
|
|
186
260
|
name: "Xiaoyi Channel",
|
|
187
261
|
description: "Xiaoyi channel plugin - Xiaoyi A2A protocol integration",
|
|
@@ -208,6 +282,11 @@ export default definePluginEntry({
|
|
|
208
282
|
registerSentinelHook(api);
|
|
209
283
|
// Cron detection hook: marks toolCallIds from cron sessions
|
|
210
284
|
registerCronDetectionHook(api);
|
|
285
|
+
// CLI exec hook: intercepts built-in exec for HarmonyOS CLI skill tools
|
|
286
|
+
registerCLIHook(api);
|
|
287
|
+
// Skills diagnostic hook: log skill usage (detected via SKILL.md reads)
|
|
288
|
+
registerSkillsDiagnosticHook(api);
|
|
211
289
|
}
|
|
212
290
|
},
|
|
213
291
|
});
|
|
292
|
+
export default pluginEntry;
|
package/dist/src/bot.d.ts
CHANGED
|
@@ -24,8 +24,3 @@ export interface HandleXYMessageParams {
|
|
|
24
24
|
* Runtime is expected to be validated before calling this function.
|
|
25
25
|
*/
|
|
26
26
|
export declare function handleXYMessage(params: HandleXYMessageParams): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* 由 provider.ts 在 wrapStreamFn 调用时触发。
|
|
29
|
-
* 这是模型 API 被调用的精确时刻,此时 isStreaming 一定为 true。
|
|
30
|
-
*/
|
|
31
|
-
export declare function notifyModelStreaming(sessionId: string): void;
|
package/dist/src/bot.js
CHANGED
|
@@ -15,6 +15,7 @@ import { selfEvolutionManager } from "./utils/self-evolution-manager.js";
|
|
|
15
15
|
import { saveRuntimeInfo } from "./utils/runtime-manager.js";
|
|
16
16
|
import { toolCallNudgeManager } from "./utils/tool-call-nudge-manager.js";
|
|
17
17
|
import { setCsplSteerContext } from "./cspl/steer-context.js";
|
|
18
|
+
import { getSteerQueue } from "./steer-queue.js";
|
|
18
19
|
import { registerTaskId, decrementTaskIdRef, hasActiveTask, } from "./task-manager.js";
|
|
19
20
|
import { logger } from "./utils/logger.js";
|
|
20
21
|
/**
|
|
@@ -241,18 +242,20 @@ export async function handleXYMessage(params) {
|
|
|
241
242
|
log.error(`[BOT] Failed to patch session model override:`, patchErr);
|
|
242
243
|
}
|
|
243
244
|
}
|
|
244
|
-
// 🔑
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
245
|
+
// 🔑 发送初始状态更新(仅首条消息,steer 不重复发送)
|
|
246
|
+
if (!isUpdate) {
|
|
247
|
+
log.log(`[BOT] Sending initial status update`);
|
|
248
|
+
void sendStatusUpdate({
|
|
249
|
+
config,
|
|
250
|
+
sessionId: parsed.sessionId,
|
|
251
|
+
taskId: parsed.taskId,
|
|
252
|
+
messageId: parsed.messageId,
|
|
253
|
+
text: "任务正在处理中,请稍候~",
|
|
254
|
+
state: "working",
|
|
255
|
+
}).catch((err) => {
|
|
256
|
+
log.error(`Failed to send initial status update:`, err);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
256
259
|
}
|
|
257
260
|
// Extract text and files from parts
|
|
258
261
|
const text = extractTextFromParts(parsed.parts);
|
|
@@ -277,49 +280,26 @@ export async function handleXYMessage(params) {
|
|
|
277
280
|
log.error(`[SELF_EVOLUTION] Failed to append inline keyword nudge: ${String(selfEvolutionError)}`);
|
|
278
281
|
}
|
|
279
282
|
}
|
|
280
|
-
//
|
|
281
|
-
//
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// 会被 globalDispatchInitGate 永久阻塞。
|
|
286
|
-
params.onInitComplete?.();
|
|
287
|
-
// Steer 也支持文件 —— 提取并下载,附带到 mediaPayload
|
|
288
|
-
const steerFileParts = extractFileParts(parsed.parts);
|
|
289
|
-
const steerDownloadedFiles = await downloadFilesFromParts(steerFileParts);
|
|
290
|
-
const steerMediaPayload = buildXYMediaPayload(steerDownloadedFiles);
|
|
291
|
-
if (steerFileParts.length > 0) {
|
|
292
|
-
log.log(`[BOT] Steer message with ${steerFileParts.length} file(s), enqueuing to streaming-signal queue`);
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
log.log(`[BOT] Steer message — enqueuing to streaming-signal queue`);
|
|
296
|
-
}
|
|
297
|
-
await enqueueSteer({
|
|
298
|
-
sessionId: parsed.sessionId,
|
|
299
|
-
sessionKey: route.sessionKey,
|
|
300
|
-
steerText: textForAgent, // 原始文本,不带 /steer 前缀
|
|
301
|
-
mediaPayload: steerMediaPayload,
|
|
302
|
-
cfg,
|
|
303
|
-
runtime,
|
|
304
|
-
parsed,
|
|
305
|
-
route,
|
|
306
|
-
deviceType,
|
|
307
|
-
});
|
|
308
|
-
log.log(`[BOT] Steer queue completed`);
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
// ── First message (non-steer) path below ──────────────────────
|
|
312
|
-
// 🔑 立即创建 streaming 信号——必须在文件下载等耗时操作之前,
|
|
313
|
-
// 否则 steer 消息的 dispatchSteerWhenReady 会找不到信号而跳过等待。
|
|
314
|
-
createStreamingSignal(parsed.sessionId);
|
|
315
|
-
// File download — only for real user messages, steer injections have no files
|
|
283
|
+
// ── Build message and dispatch via auto-reply pipeline ──────────
|
|
284
|
+
// OpenClaw's auto-reply pipeline (src/auto-reply/reply/agent-runner.ts)
|
|
285
|
+
// detects active runs and handles steer injection natively — the channel
|
|
286
|
+
// does not need its own steer detection or polling logic.
|
|
287
|
+
// File download
|
|
316
288
|
let mediaPayload = {};
|
|
317
|
-
if (!skipReg) {
|
|
289
|
+
if (!skipReg || isUpdate) {
|
|
318
290
|
const fileParts = extractFileParts(parsed.parts);
|
|
319
291
|
const downloadedFiles = await downloadFilesFromParts(fileParts);
|
|
320
292
|
log.log(`[BOT] Downloaded ${downloadedFiles.length} file(s)`);
|
|
321
293
|
mediaPayload = buildXYMediaPayload(downloadedFiles);
|
|
322
294
|
}
|
|
295
|
+
// 🔑 对于 steer 消息,将文件路径附加到消息文本中。
|
|
296
|
+
// auto-reply 管道的 steer 注入只携带 prompt 文本(followupRun.prompt),
|
|
297
|
+
// 不携带 mediaPayload,所以模型需要以文本形式看到附件路径。
|
|
298
|
+
if (isUpdate && mediaPayload.MediaPaths?.length) {
|
|
299
|
+
const fileHint = `\n【用户上传附件】:${JSON.stringify(mediaPayload.MediaPaths)}`;
|
|
300
|
+
textForAgent = `${textForAgent}${fileHint}`;
|
|
301
|
+
log.log(`[BOT] Steer: appended file paths to text`);
|
|
302
|
+
}
|
|
323
303
|
// Resolve envelope format options (following feishu pattern)
|
|
324
304
|
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(cfg);
|
|
325
305
|
// Build message body with speaker prefix (following feishu pattern)
|
|
@@ -360,8 +340,45 @@ export async function handleXYMessage(params) {
|
|
|
360
340
|
ReplyToBody: undefined, // A2A protocol doesn't support reply/quote
|
|
361
341
|
...mediaPayload,
|
|
362
342
|
});
|
|
363
|
-
// 🔑
|
|
364
|
-
|
|
343
|
+
// 🔑 Steer bypass: queue the message for agent_turn_prepare hook injection
|
|
344
|
+
// instead of going through dispatchReplyFromConfig which blocks on admitReplyTurn
|
|
345
|
+
// waiting for the active reply operation to complete.
|
|
346
|
+
//
|
|
347
|
+
// This covers BOTH:
|
|
348
|
+
// 1. Normal A2A steer (isUpdate && !skipReg) — user sends a message during
|
|
349
|
+
// an active agent run
|
|
350
|
+
// 2. CSPL/self-evolution steer (isUpdate && skipReg) — hook-triggered
|
|
351
|
+
// injection via tryInjectSteer. Without the bypass, CSPL steer would
|
|
352
|
+
// deadlock: it runs inside the agent turn, so admitReplyTurn's
|
|
353
|
+
// waitForIdle waits for the reply operation to finish, but the
|
|
354
|
+
// operation is owned by the very same agent turn.
|
|
355
|
+
//
|
|
356
|
+
// The hook fires before every agent prompt build, so the steer text reaches
|
|
357
|
+
// the model on the next turn without blocking.
|
|
358
|
+
if (isUpdate) {
|
|
359
|
+
const steerQueue = getSteerQueue();
|
|
360
|
+
// Use parsed.sessionId (A2A session UUID) as the queue key instead of
|
|
361
|
+
// route.sessionKey. The agent_turn_prepare hook looks up by ctx.sessionId
|
|
362
|
+
// which is the same A2A session UUID stored in the OpenClaw session entry.
|
|
363
|
+
// Using sessionId avoids format mismatches between the channel's route-based
|
|
364
|
+
// sessionKey and the agent runner's sessionKey.
|
|
365
|
+
const queueKey = parsed.sessionId;
|
|
366
|
+
const pending = steerQueue.get(queueKey) ?? [];
|
|
367
|
+
pending.push(textForAgent);
|
|
368
|
+
steerQueue.set(queueKey, pending);
|
|
369
|
+
log.log(`[BOT] Steer bypass: queued for agent_turn_prepare hook, queueKey=${queueKey}, sessionKey=${route.sessionKey}, queueDepth=${pending.length}, skipReg=${skipReg}`);
|
|
370
|
+
// Only decrement refCount when registerTaskId was called (non-skipReg).
|
|
371
|
+
// skipReg callers (CSPL/self-evolution) don't increment refCount.
|
|
372
|
+
if (!skipReg) {
|
|
373
|
+
decrementTaskIdRef(parsed.sessionId);
|
|
374
|
+
}
|
|
375
|
+
// Release the global dispatch init gate — steer doesn't need it.
|
|
376
|
+
params.onInitComplete?.();
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
// 🔑 For steer messages, pre-set steered=true so the dispatcher skips final
|
|
380
|
+
// response and cleanup — the first message's dispatcher handles those.
|
|
381
|
+
const steerState = { steered: isUpdate };
|
|
365
382
|
// 🔑 创建dispatcher
|
|
366
383
|
log.log(`[BOT-DISPATCHER] Creating reply dispatcher`);
|
|
367
384
|
// Cleanup: 必须在 onIdle 内部执行(参见 reply-dispatcher.ts 中 onIdleComplete 的注释)
|
|
@@ -371,7 +388,6 @@ export async function handleXYMessage(params) {
|
|
|
371
388
|
return;
|
|
372
389
|
cleaned = true;
|
|
373
390
|
log.log(`[BOT] Cleanup started`);
|
|
374
|
-
streamingSignals.delete(parsed.sessionId);
|
|
375
391
|
decrementTaskIdRef(parsed.sessionId);
|
|
376
392
|
log.log(`[BOT] Cleanup completed`);
|
|
377
393
|
};
|
|
@@ -387,8 +403,9 @@ export async function handleXYMessage(params) {
|
|
|
387
403
|
});
|
|
388
404
|
// 🔑 注册 dispatcher 的 fallback taskId 更新函数,供 steer 路径调用
|
|
389
405
|
dispatcherUpdaters.set(parsed.sessionId, updateFallbackTaskId);
|
|
390
|
-
// Steer
|
|
391
|
-
|
|
406
|
+
// Steer messages don't need a status interval — the first message's
|
|
407
|
+
// dispatcher already has one running.
|
|
408
|
+
if (!isUpdate) {
|
|
392
409
|
startStatusInterval();
|
|
393
410
|
}
|
|
394
411
|
// Build session context for AsyncLocalStorage
|
|
@@ -426,8 +443,9 @@ export async function handleXYMessage(params) {
|
|
|
426
443
|
// signal init complete to release the global dispatch gate
|
|
427
444
|
// for the next session.
|
|
428
445
|
const dispatchPromise = runWithSessionContext(sessionContext, async () => {
|
|
429
|
-
|
|
430
|
-
log.log(`[
|
|
446
|
+
const isSteerDispatch = isUpdate && !skipReg;
|
|
447
|
+
log.log(`[ALS-PROOF] bot entered dispatch scope sessionId=${sessionContext.sessionId} taskId=${sessionContext.taskId} isSteer=${isSteerDispatch}`);
|
|
448
|
+
log.log(`[BOT-DISPATCH] dispatchReplyFromConfig starting, body.length=${ctxPayload.Body?.length ?? 0}, isSteer=${isSteerDispatch}`);
|
|
431
449
|
try {
|
|
432
450
|
const result = await core.channel.reply.dispatchReplyFromConfig({
|
|
433
451
|
ctx: ctxPayload,
|
|
@@ -435,7 +453,13 @@ export async function handleXYMessage(params) {
|
|
|
435
453
|
dispatcher,
|
|
436
454
|
replyOptions,
|
|
437
455
|
});
|
|
438
|
-
|
|
456
|
+
// 区分 steer 成功(undefined)和 steer 失败/正常 run(有结果)
|
|
457
|
+
if (result === undefined) {
|
|
458
|
+
log.log(`[BOT-DISPATCH] dispatchReplyFromConfig returned undefined — steer injected successfully`);
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
log.log(`[BOT-DISPATCH] dispatchReplyFromConfig returned, resultType=${typeof result}, isSteer=${isSteerDispatch}, steered=${steerState.steered}`);
|
|
462
|
+
}
|
|
439
463
|
return result;
|
|
440
464
|
}
|
|
441
465
|
catch (dispatchErr) {
|
|
@@ -494,177 +518,12 @@ function buildXYMediaPayload(mediaList) {
|
|
|
494
518
|
MediaTypes: mediaTypes.length > 0 ? mediaTypes : undefined,
|
|
495
519
|
};
|
|
496
520
|
}
|
|
521
|
+
// ─────────────────────────────────────────────────────────────
|
|
522
|
+
// Dispatcher updaters (cross-chain taskId bridging)
|
|
523
|
+
// ─────────────────────────────────────────────────────────────
|
|
497
524
|
// Use globalThis to survive module deduplication — provider.ts may load a
|
|
498
525
|
// different copy of bot.ts, so a plain module-level Map would be two objects.
|
|
499
526
|
const _g = globalThis;
|
|
500
|
-
if (!_g.__xyStreamingSignals)
|
|
501
|
-
_g.__xyStreamingSignals = new Map();
|
|
502
|
-
if (!_g.__xySteerQueues)
|
|
503
|
-
_g.__xySteerQueues = new Map();
|
|
504
527
|
if (!_g.__xyDispatcherUpdaters)
|
|
505
528
|
_g.__xyDispatcherUpdaters = new Map();
|
|
506
|
-
const streamingSignals = _g.__xyStreamingSignals;
|
|
507
|
-
const steerQueues = _g.__xySteerQueues;
|
|
508
529
|
const dispatcherUpdaters = _g.__xyDispatcherUpdaters;
|
|
509
|
-
/**
|
|
510
|
-
* 由 provider.ts 在 wrapStreamFn 调用时触发。
|
|
511
|
-
* 这是模型 API 被调用的精确时刻,此时 isStreaming 一定为 true。
|
|
512
|
-
*/
|
|
513
|
-
export function notifyModelStreaming(sessionId) {
|
|
514
|
-
const log = logger.withContext(sessionId, "");
|
|
515
|
-
const signal = streamingSignals.get(sessionId);
|
|
516
|
-
if (signal) {
|
|
517
|
-
// 不删除 signal——后续 steer 需要靠它判断模型已在 streaming。
|
|
518
|
-
// 清理由第一条消息的 onSettled 兜底。
|
|
519
|
-
signal.notify();
|
|
520
|
-
log.log(`[STEER-QUEUE] Model streaming signal fired`);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
function createStreamingSignal(sessionId) {
|
|
524
|
-
const log = logger.withContext(sessionId, "");
|
|
525
|
-
let resolve;
|
|
526
|
-
const promise = new Promise(r => { resolve = r; });
|
|
527
|
-
const signal = { promise, notify: resolve };
|
|
528
|
-
streamingSignals.set(sessionId, signal);
|
|
529
|
-
log.log(`[STEER-QUEUE] Streaming signal created`);
|
|
530
|
-
return signal;
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* 将 steer 消息放入 per-session 串行队列。
|
|
534
|
-
* 等待第一条消息的 streaming 信号(deliver 首次触发),然后 dispatch。
|
|
535
|
-
* 多个 steer 按到达顺序串行处理,无需重试。
|
|
536
|
-
*/
|
|
537
|
-
function enqueueSteer(params) {
|
|
538
|
-
const { sessionId } = params;
|
|
539
|
-
const log = logger.withContext(sessionId, params.parsed.taskId);
|
|
540
|
-
// 取出当前队列尾部(或 undefined),然后链上新的 Promise
|
|
541
|
-
const prev = steerQueues.get(sessionId);
|
|
542
|
-
const next = (prev ?? Promise.resolve()).then(() => dispatchSteerWhenReady(params));
|
|
543
|
-
steerQueues.set(sessionId, next);
|
|
544
|
-
// 链条结束后清理
|
|
545
|
-
next.catch((err) => {
|
|
546
|
-
log.error(`[STEER-QUEUE] Steer chain failed: ${String(err)}`);
|
|
547
|
-
}).finally(() => {
|
|
548
|
-
if (steerQueues.get(sessionId) === next) {
|
|
549
|
-
steerQueues.delete(sessionId);
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
return next;
|
|
553
|
-
}
|
|
554
|
-
async function dispatchSteerWhenReady(params) {
|
|
555
|
-
const { sessionId, sessionKey, steerText } = params;
|
|
556
|
-
const log = logger.withContext(sessionId, params.parsed.taskId);
|
|
557
|
-
// 1. 等待第一条消息开始 streaming
|
|
558
|
-
// signal 可能尚未创建(第一条消息还在文件下载等耗时操作中),
|
|
559
|
-
// 轮询等待直到 signal 出现,最長等待 ~5 秒。
|
|
560
|
-
let signal = streamingSignals.get(sessionId);
|
|
561
|
-
if (!signal) {
|
|
562
|
-
log.log(`[STEER-QUEUE] Signal not yet created, polling`);
|
|
563
|
-
for (let i = 0; i < 50; i++) {
|
|
564
|
-
await new Promise(r => setTimeout(r, 100));
|
|
565
|
-
signal = streamingSignals.get(sessionId);
|
|
566
|
-
if (signal)
|
|
567
|
-
break;
|
|
568
|
-
if (!hasActiveTask(sessionId)) {
|
|
569
|
-
log.log(`[STEER-QUEUE] First message completed while waiting, skip steer`);
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
if (signal) {
|
|
575
|
-
log.log(`[STEER-QUEUE] Waiting for streaming signal`);
|
|
576
|
-
await signal.promise;
|
|
577
|
-
log.log(`[STEER-QUEUE] Streaming signal received`);
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
// 轮询超时且 hasActiveTask 仍为 true——说明第一条消息可能卡在异常路径,
|
|
581
|
-
// 没有创建 signal。此时 dispatch 会与第一条消息的模型调用并发冲突,放弃。
|
|
582
|
-
log.log(`[STEER-QUEUE] Signal never appeared after polling, skip steer to avoid collision`);
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
// 2. 第一条消息已结束 → 放弃
|
|
586
|
-
if (!hasActiveTask(sessionId)) {
|
|
587
|
-
log.log(`[STEER-QUEUE] First message completed, skip steer`);
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
// 3. 构建 dispatch 上下文并 dispatch /steer
|
|
591
|
-
const core = getXYRuntime();
|
|
592
|
-
const speaker = sessionId;
|
|
593
|
-
// 如果有文件附件,把路径拼到 steer 文本末尾,让模型通过工具读取
|
|
594
|
-
const mediaPaths = params.mediaPayload?.MediaPaths;
|
|
595
|
-
const fileHint = mediaPaths && mediaPaths.length > 0
|
|
596
|
-
? `\n【用户上传附件】:${JSON.stringify(mediaPaths)}`
|
|
597
|
-
: "";
|
|
598
|
-
const steerCommand = `/steer ${steerText}${fileHint}`;
|
|
599
|
-
const messageBody = `${speaker}: ${steerCommand}`;
|
|
600
|
-
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(params.cfg);
|
|
601
|
-
const body = core.channel.reply.formatAgentEnvelope({
|
|
602
|
-
channel: "xiaoyi-channel",
|
|
603
|
-
from: speaker,
|
|
604
|
-
timestamp: new Date(),
|
|
605
|
-
envelope: envelopeOptions,
|
|
606
|
-
body: messageBody,
|
|
607
|
-
});
|
|
608
|
-
const ctxPayload = core.channel.reply.finalizeInboundContext({
|
|
609
|
-
Body: body,
|
|
610
|
-
RawBody: steerCommand,
|
|
611
|
-
CommandBody: steerCommand,
|
|
612
|
-
From: sessionId,
|
|
613
|
-
To: sessionId,
|
|
614
|
-
SessionKey: params.route.sessionKey,
|
|
615
|
-
AccountId: params.route.accountId,
|
|
616
|
-
ChatType: "direct",
|
|
617
|
-
GroupSubject: undefined,
|
|
618
|
-
SenderName: sessionId,
|
|
619
|
-
SenderId: sessionId,
|
|
620
|
-
Provider: "xiaoyi-channel",
|
|
621
|
-
Surface: "xiaoyi-channel",
|
|
622
|
-
MessageSid: `xiaoyi_${params.parsed.taskId}_${params.deviceType}`,
|
|
623
|
-
Timestamp: Date.now(),
|
|
624
|
-
WasMentioned: false,
|
|
625
|
-
CommandAuthorized: true,
|
|
626
|
-
OriginatingChannel: "xiaoyi-channel",
|
|
627
|
-
OriginatingTo: sessionId,
|
|
628
|
-
ReplyToBody: undefined,
|
|
629
|
-
...params.mediaPayload,
|
|
630
|
-
});
|
|
631
|
-
const steerState = { steered: true };
|
|
632
|
-
const { dispatcher, replyOptions } = createXYReplyDispatcher({
|
|
633
|
-
cfg: params.cfg,
|
|
634
|
-
runtime: params.runtime,
|
|
635
|
-
sessionId,
|
|
636
|
-
taskId: params.parsed.taskId,
|
|
637
|
-
messageId: params.parsed.messageId,
|
|
638
|
-
accountId: params.route.accountId,
|
|
639
|
-
steerState,
|
|
640
|
-
});
|
|
641
|
-
const sessionContext = {
|
|
642
|
-
config: resolveXYConfig(params.cfg),
|
|
643
|
-
sessionId,
|
|
644
|
-
taskId: params.parsed.taskId,
|
|
645
|
-
messageId: params.parsed.messageId,
|
|
646
|
-
agentId: params.route.accountId,
|
|
647
|
-
deviceType: params.deviceType,
|
|
648
|
-
};
|
|
649
|
-
log.log(`[STEER-QUEUE] Dispatching steer`);
|
|
650
|
-
await core.channel.reply.withReplyDispatcher({
|
|
651
|
-
dispatcher,
|
|
652
|
-
onSettled: () => {
|
|
653
|
-
log.log(`[STEER-QUEUE] Steer dispatch settled`);
|
|
654
|
-
},
|
|
655
|
-
run: () => {
|
|
656
|
-
return runWithSessionContext(sessionContext, async () => {
|
|
657
|
-
log.log(`[ALS-PROOF] bot entered steer dispatch scope sessionId=${sessionContext.sessionId} taskId=${sessionContext.taskId} isSteer=true`);
|
|
658
|
-
const result = await core.channel.reply.dispatchReplyFromConfig({
|
|
659
|
-
ctx: ctxPayload,
|
|
660
|
-
cfg: params.cfg,
|
|
661
|
-
dispatcher,
|
|
662
|
-
replyOptions,
|
|
663
|
-
});
|
|
664
|
-
log.log(`[STEER-QUEUE] dispatch result: ${JSON.stringify(result)}`);
|
|
665
|
-
return result;
|
|
666
|
-
});
|
|
667
|
-
},
|
|
668
|
-
});
|
|
669
|
-
log.log(`[STEER-QUEUE] Steer dispatch completed`);
|
|
670
|
-
}
|
package/dist/src/channel.js
CHANGED
|
@@ -27,6 +27,7 @@ import { discoverCrossDevicesTool } from "./tools/discover-cross-devices-tool.js
|
|
|
27
27
|
import { sendCrossDeviceTaskTool } from "./tools/send-cross-device-task-tool.js";
|
|
28
28
|
import { displayA2UICardByPathTool } from "./tools/display-a2ui-card-bypath-tool.js";
|
|
29
29
|
import { checkPluginPrivilegeTool } from "./tools/check-plugin-privilege-tool.js";
|
|
30
|
+
import { invokeTool } from "./tools/invoke.js";
|
|
30
31
|
const ALL_TOOLS = [
|
|
31
32
|
locationTool,
|
|
32
33
|
discoverCrossDevicesTool,
|
|
@@ -50,6 +51,7 @@ const ALL_TOOLS = [
|
|
|
50
51
|
loginTokenTool,
|
|
51
52
|
agentAsSkillTool,
|
|
52
53
|
checkPluginPrivilegeTool,
|
|
54
|
+
invokeTool,
|
|
53
55
|
];
|
|
54
56
|
/**
|
|
55
57
|
* Xiaoyi Channel Plugin for OpenClaw.
|
|
@@ -126,14 +128,27 @@ export const xyPlugin = {
|
|
|
126
128
|
? { conversationId, matchPriority: 2 }
|
|
127
129
|
: null;
|
|
128
130
|
},
|
|
129
|
-
resolveCommandConversation: ({ accountId }) => {
|
|
131
|
+
resolveCommandConversation: ({ accountId, sessionKey }) => {
|
|
130
132
|
// xiaoyi-channel: the A2A sessionId IS the conversationId.
|
|
131
|
-
//
|
|
133
|
+
// 1. Prefer the current ALS session context (works when the command
|
|
134
|
+
// is processed inside an active A2A message-handling turn).
|
|
132
135
|
const ctx = getCurrentSessionContext();
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
return
|
|
136
|
-
|
|
136
|
+
const alsSessionId = ctx?.sessionId?.trim();
|
|
137
|
+
if (alsSessionId)
|
|
138
|
+
return { conversationId: alsSessionId };
|
|
139
|
+
// 2. Fall back to parsing the session key. For xiaoyi-channel the
|
|
140
|
+
// session key has the form:
|
|
141
|
+
// agent:<agentId>:xiaoyi-channel:<accountId>:<sessionId>
|
|
142
|
+
// The last `:`-delimited segment is the A2A sessionId.
|
|
143
|
+
if (sessionKey) {
|
|
144
|
+
const lastColon = sessionKey.lastIndexOf(":");
|
|
145
|
+
if (lastColon >= 0) {
|
|
146
|
+
const sessionId = sessionKey.slice(lastColon + 1).trim();
|
|
147
|
+
if (sessionId)
|
|
148
|
+
return { conversationId: sessionId };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
137
152
|
},
|
|
138
153
|
},
|
|
139
154
|
reload: {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ApiResponse } from './constants.js';
|
|
2
|
-
export declare function callApi(
|
|
2
|
+
export declare function callApi(payload: object, api: any, sessionId: string): Promise<ApiResponse>;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import https from 'https';
|
|
5
5
|
import { URL } from 'url';
|
|
6
|
-
import { getConfig } from './config.js';
|
|
7
|
-
import { DEFAULT_HTTPS_PORT, HTTP_STATUS_BAD_REQUEST, API_URL_SUFFIX } from './constants.js';
|
|
8
6
|
import { logger } from '../utils/logger.js';
|
|
7
|
+
import { getConfig } from './config.js';
|
|
8
|
+
import { DEFAULT_HTTPS_PORT, DEFAULT_HTTP_PORT, HTTP_STATUS_BAD_REQUEST, API_URL_SUFFIX } from './constants.js';
|
|
9
9
|
function buildHeadersForCelia(config, sessionId) {
|
|
10
10
|
if (!config.uid || !config.apiKey || !config.skillId || !config.requestFrom) {
|
|
11
11
|
throw new Error('[SENTINEL HOOK] Missing required configuration: uid, apiKey, skillId, or requestFrom is not defined');
|
|
@@ -23,7 +23,7 @@ function buildRequestOptions(url, headers, timeout) {
|
|
|
23
23
|
const urlObj = new URL(url);
|
|
24
24
|
return {
|
|
25
25
|
hostname: urlObj.hostname,
|
|
26
|
-
port: urlObj.port || DEFAULT_HTTPS_PORT,
|
|
26
|
+
port: urlObj.port || (urlObj.protocol === 'https:' ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT),
|
|
27
27
|
path: urlObj.pathname,
|
|
28
28
|
method: "POST",
|
|
29
29
|
headers: headers,
|
|
@@ -70,6 +70,7 @@ function handleResponse(res, resolve, reject) {
|
|
|
70
70
|
data += chunk;
|
|
71
71
|
});
|
|
72
72
|
res.on('end', () => {
|
|
73
|
+
logger.log(`[SENTINEL HOOK] callApi response body: ${data}`);
|
|
73
74
|
try {
|
|
74
75
|
const result = parseResponseData(data);
|
|
75
76
|
resolve(result);
|
|
@@ -79,18 +80,15 @@ function handleResponse(res, resolve, reject) {
|
|
|
79
80
|
}
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
|
-
export async function callApi(
|
|
83
|
+
export async function callApi(payload, api, sessionId) {
|
|
83
84
|
const config = getConfig(api);
|
|
84
85
|
const headersForCelia = buildHeadersForCelia(config, sessionId);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
action: action,
|
|
89
|
-
extra: `${JSON.stringify({ userId: config.uid })}`
|
|
90
|
-
};
|
|
91
|
-
const httpBody = JSON.stringify(payload);
|
|
86
|
+
// 确保 uid 存在于消息体中(从 config 注入)
|
|
87
|
+
const payloadWithUid = { ...payload, uid: config.uid };
|
|
88
|
+
const httpBody = JSON.stringify(payloadWithUid);
|
|
92
89
|
const apiUrl = `${config.api.url}${API_URL_SUFFIX}`;
|
|
93
|
-
logger.log(`[SENTINEL HOOK] callApi:
|
|
90
|
+
logger.log(`[SENTINEL HOOK] callApi URL: ${apiUrl}`);
|
|
91
|
+
logger.log(`[SENTINEL HOOK] callApi request body: ${httpBody}`);
|
|
94
92
|
return new Promise((resolve, reject) => {
|
|
95
93
|
const options = buildRequestOptions(apiUrl, headersForCelia, config.api.timeout);
|
|
96
94
|
const req = https.request(options, (res) => {
|