@ynhcj/xiaoyi-channel 0.0.26-beta → 0.0.26-release2026060602
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 +2 -15
- package/dist/index.js +534 -10
- package/dist/provider-discovery.d.ts +2 -0
- package/dist/provider-discovery.js +4 -0
- package/dist/src/acp-session-binding.d.ts +37 -0
- package/dist/src/acp-session-binding.js +237 -0
- package/dist/src/approval-bridge.d.ts +48 -0
- package/dist/src/approval-bridge.js +382 -0
- package/dist/src/bot.d.ts +9 -0
- package/dist/src/bot.js +380 -152
- package/dist/src/channel.js +107 -19
- package/dist/src/client.d.ts +4 -3
- package/dist/src/client.js +34 -61
- package/dist/src/compaction-provider.d.ts +50 -0
- package/dist/src/compaction-provider.js +202 -0
- package/dist/src/config-schema.d.ts +20 -0
- package/dist/src/config-schema.js +20 -0
- package/dist/src/config.js +3 -2
- package/dist/src/conversation/conversation-manager.d.ts +96 -0
- package/dist/src/conversation/conversation-manager.js +472 -0
- package/dist/src/conversation/conversation-session.d.ts +60 -0
- package/dist/src/conversation/conversation-session.js +22 -0
- package/dist/src/conversation/cron-buffer.d.ts +50 -0
- package/dist/src/conversation/cron-buffer.js +269 -0
- package/dist/src/conversation/outbound-gateway.d.ts +43 -0
- package/dist/src/conversation/outbound-gateway.js +81 -0
- package/dist/src/conversation/outbound-queue.d.ts +35 -0
- package/dist/src/conversation/outbound-queue.js +96 -0
- package/dist/src/conversation/steer-service.d.ts +29 -0
- package/dist/src/conversation/steer-service.js +52 -0
- package/dist/src/conversation/stream-assembler.d.ts +52 -0
- package/dist/src/conversation/stream-assembler.js +122 -0
- package/dist/src/cron-command.d.ts +17 -0
- package/dist/src/cron-command.js +33 -0
- package/dist/src/cron-query-handler.d.ts +27 -0
- package/dist/src/cron-query-handler.js +615 -0
- package/dist/src/cron-recovery.d.ts +25 -0
- package/dist/src/cron-recovery.js +587 -0
- package/dist/src/cspl/call_api.d.ts +8 -0
- package/dist/src/cspl/call_api.js +143 -0
- package/dist/src/cspl/config.d.ts +15 -0
- package/dist/src/cspl/config.js +119 -0
- package/dist/src/cspl/configs.json +10 -0
- package/dist/src/cspl/constants.d.ts +106 -0
- package/dist/src/cspl/constants.js +75 -0
- package/dist/src/cspl/sentinel_hook.d.ts +2 -0
- package/dist/src/cspl/sentinel_hook.js +105 -0
- package/dist/src/cspl/skill_scope_hook.d.ts +17 -0
- package/dist/src/cspl/skill_scope_hook.js +125 -0
- package/dist/src/cspl/steer-context.d.ts +21 -0
- package/dist/src/cspl/steer-context.js +78 -0
- package/dist/src/cspl/upload_file.d.ts +1 -0
- package/dist/src/cspl/upload_file.js +213 -0
- package/dist/src/cspl/utils.d.ts +46 -0
- package/dist/src/cspl/utils.js +470 -0
- package/dist/src/dispatch/bot.d.ts +20 -0
- package/dist/src/dispatch/bot.js +550 -0
- package/dist/src/dispatch/monitor.d.ts +17 -0
- package/dist/src/dispatch/monitor.js +333 -0
- package/dist/src/dispatch/outbound.d.ts +7 -0
- package/dist/src/dispatch/outbound.js +281 -0
- package/dist/src/dispatch/reply-dispatcher.d.ts +22 -0
- package/dist/src/dispatch/reply-dispatcher.js +633 -0
- package/dist/src/dynamic-skill-trigger.d.ts +8 -0
- package/dist/src/dynamic-skill-trigger.js +62 -0
- package/dist/src/file-download.d.ts +1 -0
- package/dist/src/file-download.js +3 -4
- package/dist/src/file-upload.d.ts +18 -0
- package/dist/src/file-upload.js +257 -17
- package/dist/src/formatter.d.ts +95 -1
- package/dist/src/formatter.js +312 -133
- package/dist/src/heartbeat.js +4 -7
- 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 +210 -0
- 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 +6 -0
- package/dist/src/log-reporter/reporter.js +56 -0
- package/dist/src/log-reporter/scanner.d.ts +10 -0
- package/dist/src/log-reporter/scanner.js +78 -0
- package/dist/src/log-reporter/types.d.ts +58 -0
- package/dist/src/log-reporter/types.js +2 -0
- package/dist/src/log-reporter/uploader.d.ts +7 -0
- package/dist/src/log-reporter/uploader.js +55 -0
- package/dist/src/login-token-handler.d.ts +8 -0
- package/dist/src/login-token-handler.js +63 -0
- package/dist/src/memory-query-handler.d.ts +1 -0
- package/dist/src/memory-query-handler.js +283 -0
- package/dist/src/message-queue.d.ts +17 -0
- package/dist/src/message-queue.js +52 -0
- package/dist/src/monitor.js +169 -57
- package/dist/src/onboarding.d.ts +3 -4
- package/dist/src/onboarding.js +2 -2
- package/dist/src/outbound.d.ts +2 -1
- package/dist/src/outbound.js +70 -41
- package/dist/src/parser.d.ts +33 -1
- package/dist/src/parser.js +135 -0
- package/dist/src/provider.d.ts +3 -0
- package/dist/src/provider.js +1009 -0
- package/dist/src/push.d.ts +19 -2
- package/dist/src/push.js +128 -56
- package/dist/src/reply-dispatcher.d.ts +10 -1
- package/dist/src/reply-dispatcher.js +425 -171
- package/dist/src/runtime.d.ts +3 -11
- package/dist/src/runtime.js +6 -18
- package/dist/src/self-evolution-handler.d.ts +7 -0
- package/dist/src/self-evolution-handler.js +149 -0
- package/dist/src/self-evolution-keyword.d.ts +9 -0
- package/dist/src/self-evolution-keyword.js +147 -0
- package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
- package/dist/src/self-evolution-tool-result-nudge.js +96 -0
- package/dist/src/sensitive-redactor.d.ts +4 -0
- package/dist/src/sensitive-redactor.js +364 -0
- package/dist/src/skill-retriever/config.d.ts +4 -0
- package/dist/src/skill-retriever/config.js +25 -0
- package/dist/src/skill-retriever/hooks.d.ts +39 -0
- package/dist/src/skill-retriever/hooks.js +224 -0
- package/dist/src/skill-retriever/skill-status.d.ts +22 -0
- package/dist/src/skill-retriever/skill-status.js +125 -0
- package/dist/src/skill-retriever/tool-search.d.ts +27 -0
- package/dist/src/skill-retriever/tool-search.js +330 -0
- package/dist/src/skill-retriever/types.d.ts +38 -0
- package/dist/src/skill-retriever/types.js +1 -0
- package/dist/src/subagent-wait-state.d.ts +73 -0
- package/dist/src/subagent-wait-state.js +240 -0
- package/dist/src/task-manager.d.ts +20 -32
- package/dist/src/task-manager.js +69 -88
- package/dist/src/tools/agent-as-skill-tool.d.ts +46 -0
- package/dist/src/tools/agent-as-skill-tool.js +183 -0
- package/dist/src/tools/calendar-tool.d.ts +24 -1
- package/dist/src/tools/calendar-tool.js +13 -47
- package/dist/src/tools/call-device-tool.d.ts +20 -0
- package/dist/src/tools/call-device-tool.js +153 -0
- package/dist/src/tools/call-phone-tool.d.ts +24 -0
- package/dist/src/tools/call-phone-tool.js +124 -0
- package/dist/src/tools/check-plugin-privilege-tool.d.ts +20 -0
- package/dist/src/tools/check-plugin-privilege-tool.js +180 -0
- package/dist/src/tools/create-alarm-tool.d.ts +45 -0
- package/dist/src/tools/create-alarm-tool.js +333 -0
- package/dist/src/tools/delete-alarm-tool.d.ts +25 -0
- package/dist/src/tools/delete-alarm-tool.js +170 -0
- package/dist/src/tools/device-tool-map.d.ts +4 -0
- package/dist/src/tools/device-tool-map.js +45 -0
- package/dist/src/tools/discover-cross-devices-tool.d.ts +16 -0
- package/dist/src/tools/discover-cross-devices-tool.js +232 -0
- package/dist/src/tools/display-a2ui-card-bypath-tool.d.ts +21 -0
- package/dist/src/tools/display-a2ui-card-bypath-tool.js +98 -0
- package/dist/src/tools/get-alarm-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-alarm-tool-schema.js +11 -0
- package/dist/src/tools/get-calendar-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-calendar-tool-schema.js +9 -0
- package/dist/src/tools/get-collection-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-collection-tool-schema.js +10 -0
- package/dist/src/tools/get-contact-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-contact-tool-schema.js +11 -0
- package/dist/src/tools/get-device-file-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-device-file-tool-schema.js +10 -0
- package/dist/src/tools/get-email-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-email-tool-schema.js +9 -0
- package/dist/src/tools/get-note-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-note-tool-schema.js +10 -0
- package/dist/src/tools/get-photo-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-photo-tool-schema.js +10 -0
- package/dist/src/tools/hmos-cli.d.ts +109 -0
- package/dist/src/tools/hmos-cli.js +558 -0
- package/dist/src/tools/image-reading-tool.d.ts +32 -0
- package/dist/src/tools/image-reading-tool.js +246 -0
- package/dist/src/tools/invoke.d.ts +88 -0
- package/dist/src/tools/invoke.js +1213 -0
- package/dist/src/tools/location-tool.d.ts +11 -1
- package/dist/src/tools/location-tool.js +17 -49
- package/dist/src/tools/login-token-tool.d.ts +24 -0
- package/dist/src/tools/login-token-tool.js +142 -0
- package/dist/src/tools/modify-alarm-tool.d.ts +55 -0
- package/dist/src/tools/modify-alarm-tool.js +364 -0
- package/dist/src/tools/modify-note-tool.d.ts +20 -1
- package/dist/src/tools/modify-note-tool.js +11 -50
- package/dist/src/tools/note-tool.d.ts +20 -1
- package/dist/src/tools/note-tool.js +38 -30
- package/dist/src/tools/query-app-message-tool.d.ts +31 -0
- package/dist/src/tools/query-app-message-tool.js +138 -0
- package/dist/src/tools/query-memory-data-tool.d.ts +31 -0
- package/dist/src/tools/query-memory-data-tool.js +154 -0
- package/dist/src/tools/query-todo-task-tool.d.ts +27 -0
- package/dist/src/tools/query-todo-task-tool.js +133 -0
- package/dist/src/tools/save-file-to-phone-tool.d.ts +28 -0
- package/dist/src/tools/save-file-to-phone-tool.js +165 -0
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +28 -0
- package/dist/src/tools/save-media-to-gallery-tool.js +173 -0
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +54 -0
- package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
- package/dist/src/tools/schema-tool-factory.d.ts +27 -0
- package/dist/src/tools/schema-tool-factory.js +32 -0
- package/dist/src/tools/search-alarm-tool.d.ts +41 -0
- package/dist/src/tools/search-alarm-tool.js +277 -0
- package/dist/src/tools/search-calendar-tool.d.ts +24 -1
- package/dist/src/tools/search-calendar-tool.js +18 -91
- package/dist/src/tools/search-contact-tool.d.ts +16 -1
- package/dist/src/tools/search-contact-tool.js +10 -64
- package/dist/src/tools/search-email-tool.d.ts +25 -0
- package/dist/src/tools/search-email-tool.js +136 -0
- package/dist/src/tools/search-file-tool.d.ts +20 -0
- package/dist/src/tools/search-file-tool.js +125 -0
- package/dist/src/tools/search-message-tool.d.ts +20 -0
- package/dist/src/tools/search-message-tool.js +116 -0
- package/dist/src/tools/search-note-tool.d.ts +16 -1
- package/dist/src/tools/search-note-tool.js +12 -31
- package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -1
- package/dist/src/tools/search-photo-gallery-tool.js +48 -70
- package/dist/src/tools/send-cross-device-task-tool.d.ts +35 -0
- package/dist/src/tools/send-cross-device-task-tool.js +365 -0
- package/dist/src/tools/send-email-tool.d.ts +27 -0
- package/dist/src/tools/send-email-tool.js +134 -0
- package/dist/src/tools/send-file-to-user-tool.d.ts +24 -0
- package/dist/src/tools/send-file-to-user-tool.js +306 -0
- package/dist/src/tools/send-html-card-tool.d.ts +25 -0
- package/dist/src/tools/send-html-card-tool.js +130 -0
- package/dist/src/tools/send-message-tool.d.ts +24 -0
- package/dist/src/tools/send-message-tool.js +139 -0
- package/dist/src/tools/session-manager.d.ts +52 -18
- package/dist/src/tools/session-manager.js +194 -83
- package/dist/src/tools/timestamp-to-utc8-tool.d.ts +12 -0
- package/dist/src/tools/timestamp-to-utc8-tool.js +104 -0
- package/dist/src/tools/upload-file-tool.d.ts +32 -0
- package/dist/src/tools/upload-file-tool.js +216 -0
- package/dist/src/tools/upload-photo-tool.d.ts +20 -1
- package/dist/src/tools/upload-photo-tool.js +14 -57
- package/dist/src/tools/view-push-result-tool.d.ts +5 -0
- package/dist/src/tools/view-push-result-tool.js +107 -0
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +35 -0
- package/dist/src/tools/xiaoyi-add-collection-tool.js +192 -0
- package/dist/src/tools/xiaoyi-append-reference.d.ts +47 -0
- package/dist/src/tools/xiaoyi-append-reference.js +107 -0
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +24 -0
- package/dist/src/tools/xiaoyi-collection-tool.js +147 -0
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +18 -0
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +162 -0
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +16 -1
- package/dist/src/tools/xiaoyi-gui-tool.js +23 -44
- package/dist/src/transport/client.d.ts +36 -0
- package/dist/src/transport/client.js +120 -0
- package/dist/src/transport/heartbeat.d.ts +39 -0
- package/dist/src/transport/heartbeat.js +99 -0
- package/dist/src/transport/message-queue.d.ts +17 -0
- package/dist/src/transport/message-queue.js +52 -0
- package/dist/src/transport/push.d.ts +42 -0
- package/dist/src/transport/push.js +226 -0
- package/dist/src/transport/websocket.d.ts +142 -0
- package/dist/src/transport/websocket.js +899 -0
- package/dist/src/trigger-handler.d.ts +22 -0
- package/dist/src/trigger-handler.js +55 -0
- package/dist/src/types.d.ts +33 -9
- package/dist/src/types.js +4 -0
- package/dist/src/utils/async-mutex.d.ts +5 -0
- package/dist/src/utils/async-mutex.js +14 -0
- package/dist/src/utils/config-manager.d.ts +3 -2
- package/dist/src/utils/config-manager.js +25 -8
- package/dist/src/utils/cron-push-map.d.ts +26 -0
- package/dist/src/utils/cron-push-map.js +139 -0
- package/dist/src/utils/logger.d.ts +8 -0
- package/dist/src/utils/logger.js +128 -18
- package/dist/src/utils/pushdata-manager.d.ts +36 -0
- package/dist/src/utils/pushdata-manager.js +176 -0
- package/dist/src/utils/pushid-manager.d.ts +12 -0
- package/dist/src/utils/pushid-manager.js +104 -0
- package/dist/src/utils/runtime-manager.d.ts +7 -0
- package/dist/src/utils/runtime-manager.js +61 -0
- package/dist/src/utils/self-evolution-manager.d.ts +10 -0
- package/dist/src/utils/self-evolution-manager.js +69 -0
- package/dist/src/utils/skills-logger.d.ts +5 -0
- package/dist/src/utils/skills-logger.js +76 -0
- package/dist/src/utils/throw.d.ts +5 -0
- package/dist/src/utils/throw.js +10 -0
- package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
- package/dist/src/utils/tool-call-nudge-manager.js +47 -0
- package/dist/src/websocket.d.ts +32 -32
- package/dist/src/websocket.js +567 -288
- package/openclaw.plugin.json +26 -0
- package/package.json +9 -8
- package/dist/src/tools/search-photo-tool.d.ts +0 -9
- package/dist/src/tools/search-photo-tool.js +0 -270
- package/dist/src/utils/session.d.ts +0 -34
- package/dist/src/utils/session.js +0 -50
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Xiaoyi Channel Plugin Entry Point.
|
|
5
|
-
* Exports the plugin for OpenClaw to load.
|
|
6
|
-
* Located at root level following feishu pattern for proper plugin registration.
|
|
7
|
-
*/
|
|
8
|
-
declare const plugin: {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
description: string;
|
|
12
|
-
configSchema: import("openclaw/plugin-sdk").OpenClawPluginConfigSchema;
|
|
13
|
-
register(api: OpenClawPluginApi): void;
|
|
14
|
-
};
|
|
1
|
+
import { type OpenClawPluginDefinition } from "openclaw/plugin-sdk/core";
|
|
2
|
+
declare const plugin: OpenClawPluginDefinition;
|
|
15
3
|
export default plugin;
|
|
16
|
-
export { xyPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,545 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/core";
|
|
2
|
+
import { xiaoyiProvider } from "./src/provider.js";
|
|
3
|
+
import { xiaoyiCompactionProvider } from "./src/compaction-provider.js";
|
|
2
4
|
import { xyPlugin } from "./src/channel.js";
|
|
5
|
+
import registerSentinelHook from "./src/cspl/sentinel_hook.js";
|
|
6
|
+
import registerSkillScopeHook from "./src/cspl/skill_scope_hook.js";
|
|
3
7
|
import { setXYRuntime } from "./src/runtime.js";
|
|
8
|
+
import { markCronToolCall, clearCronToolCall, getCurrentSessionContext, setCronToolRunInfo, clearCronToolRunInfo, isCronActive } from "./src/tools/session-manager.js";
|
|
9
|
+
import { configManager } from "./src/utils/config-manager.js";
|
|
10
|
+
import { setJobPushId } from "./src/utils/cron-push-map.js";
|
|
11
|
+
import { getAllPushIds } from "./src/utils/pushid-manager.js";
|
|
12
|
+
import { registerSelfEvolutionToolResultNudge } from "./src/self-evolution-tool-result-nudge.js";
|
|
13
|
+
import { createBeforePromptBuildHandler } from "./src/skill-retriever/hooks.js";
|
|
14
|
+
import { normalizeToolRetrieverConfig } from "./src/skill-retriever/config.js";
|
|
15
|
+
import { registerCLIHook } from "./src/tools/hmos-cli.js";
|
|
16
|
+
import { recoverCronState } from "./src/cron-recovery.js";
|
|
17
|
+
import { writeSkillUsage } from "./src/utils/skills-logger.js";
|
|
18
|
+
import { markSubagentSpawned, markSubagentEnded, deliverSubagentFinalResult, } from "./src/conversation/conversation-manager.js";
|
|
19
|
+
import { notifyCronAgentEnd } from "./src/conversation/cron-buffer.js";
|
|
20
|
+
import { logger } from "./src/utils/logger.js";
|
|
4
21
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
22
|
+
* Parse a file path string to detect if it refers to a SKILL.md file within
|
|
23
|
+
* a skills directory. Returns the skill name (parent directory) if so.
|
|
24
|
+
*
|
|
25
|
+
* Matches paths like:
|
|
26
|
+
* ~/.openclaw/workspace/skills/my-skill/SKILL.md
|
|
27
|
+
* /home/user/core_skills/my-skill/SKILL.md
|
|
28
|
+
* skills/my-skill/SKILL.md
|
|
8
29
|
*/
|
|
9
|
-
|
|
30
|
+
function extractSkillNameFromPath(filePath) {
|
|
31
|
+
if (typeof filePath !== "string" || !filePath)
|
|
32
|
+
return null;
|
|
33
|
+
// Normalize common path prefixes
|
|
34
|
+
const normalized = filePath.replace(/^~\//, "/home/").replace(/\\/g, "/");
|
|
35
|
+
// Match: .../skills/<skillName>/SKILL.md or .../skills/<skillName>/...
|
|
36
|
+
// Also match: .../core_skills/<skillName>/SKILL.md
|
|
37
|
+
const match = normalized.match(/\/(?:core_)?skills\/([^/]+)\/SKILL\.md$/i);
|
|
38
|
+
return match ? match[1] : null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Register the skills diagnostic event listener via after_tool_call hook.
|
|
42
|
+
*
|
|
43
|
+
* When openclaw fires a `skill.used` diagnostic event, the skill's SKILL.md
|
|
44
|
+
* is typically read by the model first. We detect SKILL.md reads through
|
|
45
|
+
* the `after_tool_call` hook and write the skill name to the skills log.
|
|
46
|
+
*/
|
|
47
|
+
function registerSkillsDiagnosticHook(api) {
|
|
48
|
+
// Skill name → tool names mapping for direct tool-based skill usage logging
|
|
49
|
+
const SKILL_TOOLS = {
|
|
50
|
+
GetCurrentLocation: ["get_user_location"],
|
|
51
|
+
Schedule: ["create_calendar_event", "search_calendar_event"],
|
|
52
|
+
memorandum: ["create_note", "search_notes", "modify_note"],
|
|
53
|
+
gallery: ["search_photo_gallery", "save_media_to_gallery"],
|
|
54
|
+
contact: ["search_contact"],
|
|
55
|
+
file: ["search_file", "upload_file", "save_file_to_file_manager"],
|
|
56
|
+
clock: ["create_alarm", "delete_alarm", "search_alarm", "modify_alarm"],
|
|
57
|
+
message: ["search_message", "send_message"],
|
|
58
|
+
phone: ["call_phone"],
|
|
59
|
+
"xiaoyi-collection": ["add_collection", "query_collection", "delete_collection"],
|
|
60
|
+
"xiaoyi-image-understanding": ["image_reading"],
|
|
61
|
+
};
|
|
62
|
+
// Inverted to tool name → skill name for lookup
|
|
63
|
+
const TOOL_SKILL_MAP = Object.fromEntries(Object.entries(SKILL_TOOLS).flatMap(([skill, tools]) => tools.map((t) => [t, skill])));
|
|
64
|
+
// Resolve the actual tool name from call_device_tool wrapper.
|
|
65
|
+
// The model calls call_device_tool({ toolName: "...", arguments: {...} })
|
|
66
|
+
// — the real tool name is inside params, not event.toolName.
|
|
67
|
+
function resolveActualToolName(event) {
|
|
68
|
+
if (event.toolName === "call_device_tool") {
|
|
69
|
+
const inner = event.params?.toolName;
|
|
70
|
+
if (typeof inner === "string" && inner.length > 0)
|
|
71
|
+
return inner;
|
|
72
|
+
}
|
|
73
|
+
return event.toolName;
|
|
74
|
+
}
|
|
75
|
+
// Log skill usage for known device tools on before_tool_call
|
|
76
|
+
api.on("before_tool_call", async (event, _ctx) => {
|
|
77
|
+
const actualToolName = resolveActualToolName(event);
|
|
78
|
+
const skillName = TOOL_SKILL_MAP[actualToolName];
|
|
79
|
+
if (skillName) {
|
|
80
|
+
writeSkillUsage(skillName);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// Detect SKILL.md reads on after_tool_call (original behavior)
|
|
84
|
+
api.on("after_tool_call", async (event, _ctx) => {
|
|
85
|
+
if (event.toolName === "read") {
|
|
86
|
+
const skillName = extractSkillNameFromPath(event.params?.path);
|
|
87
|
+
if (skillName) {
|
|
88
|
+
writeSkillUsage(skillName);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 从 openclaw sessionKey 解析 cron jobId。
|
|
95
|
+
* 格式形如 `agent:<agentId>:cron:<jobId>:run:<startedAtTs>`(隔离 run 为
|
|
96
|
+
* `cron:<jobId>`),jobId 位于 "cron:" 之后到下一个冒号/空白之前。
|
|
97
|
+
*/
|
|
98
|
+
function parseCronJobIdFromSessionKey(sessionKey) {
|
|
99
|
+
const match = sessionKey.match(/cron:([^:\s]+)/);
|
|
100
|
+
return match ? match[1] : undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Register the cron detection hook.
|
|
104
|
+
*
|
|
105
|
+
* When openclaw's cron runner triggers a tool call, the sessionKey has the
|
|
106
|
+
* format "cron:<jobId>"(或 agent 展开后的 `agent:<id>:cron:<jobId>:run:<ts>`)。
|
|
107
|
+
* We use this to mark the toolCallId in a global Map
|
|
108
|
+
* so that sendCommand() can route the command through the push channel
|
|
109
|
+
* instead of the (non-existent) WebSocket session.
|
|
110
|
+
*/
|
|
111
|
+
function registerCronDetectionHook(api) {
|
|
112
|
+
api.on("before_tool_call", async (event, ctx) => {
|
|
113
|
+
// sessionKey 前缀依赖 openclaw 版本行为,不一定可靠;isCronActive(jobId)
|
|
114
|
+
// 按 jobId 精确判断(provider 已从消息 [cron:...] 标记过该 job),替代
|
|
115
|
+
// 原先的全局 120s 时间戳,避免把普通对话/其它 job 的工具调用误判为 cron。
|
|
116
|
+
const sessionKey = ctx.sessionKey ?? "";
|
|
117
|
+
const sessionJobId = parseCronJobIdFromSessionKey(sessionKey);
|
|
118
|
+
if ((sessionKey.includes("cron:") || isCronActive(sessionJobId)) && event.toolCallId) {
|
|
119
|
+
markCronToolCall(event.toolCallId);
|
|
120
|
+
// 存储 runId,供 call_device_tool 在 ALS 缺失时构造合成 SessionContext
|
|
121
|
+
if (event.runId) {
|
|
122
|
+
setCronToolRunInfo(event.toolCallId, event.runId);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
api.on("after_tool_call", async (event, ctx) => {
|
|
127
|
+
if (event.toolCallId) {
|
|
128
|
+
clearCronToolCall(event.toolCallId);
|
|
129
|
+
clearCronToolRunInfo(event.toolCallId);
|
|
130
|
+
}
|
|
131
|
+
// 捕获对话创建的 cron job:agent 调 cron(add) 后,从 result 拿 jobId,
|
|
132
|
+
// 配合当前会话的 pushId,写入 jobId↔pushId 映射,供 fire 时反查设备。
|
|
133
|
+
await captureCronAddMapping(event, ctx).catch((err) => {
|
|
134
|
+
// 捕获失败不影响工具结果
|
|
135
|
+
console.error("[xy] captureCronAddMapping failed:", err);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/** 从 cron add 工具结果中提取 jobId 并写入 pushId 映射。 */
|
|
140
|
+
async function captureCronAddMapping(event, ctx) {
|
|
141
|
+
// 两条创建路径都要捕获:
|
|
142
|
+
// 1) cron agent 工具:toolName==="cron", params.action==="add"
|
|
143
|
+
// 2) exec 跑 CLI:toolName==="exec", params.command 含 "cron add"
|
|
144
|
+
// (agent 实际用的是这条:openclaw cron add --name ... --cron ... --message ...)
|
|
145
|
+
const isCronAddTool = event.toolName === "cron" &&
|
|
146
|
+
(event.params?.action === "add" || event.params?.action === "create");
|
|
147
|
+
const isExecCronAdd = event.toolName === "exec" && isExecCronAddCommand(event.params?.command);
|
|
148
|
+
if (!isCronAddTool && !isExecCronAdd)
|
|
149
|
+
return;
|
|
150
|
+
console.log(`[CRONMAP] after_tool_call path=${event.toolName}, resultType=${typeof event.result}`);
|
|
151
|
+
const jobId = readJobIdFromResult(event.result);
|
|
152
|
+
if (!jobId) {
|
|
153
|
+
console.log(`[CRONMAP] skip: could not extract jobId. preview=${preview(event.result)}`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
console.log(`[CRONMAP] extracted jobId=${jobId}`);
|
|
157
|
+
const sessionCtx = getCurrentSessionContext();
|
|
158
|
+
const sessionId = sessionCtx?.sessionId;
|
|
159
|
+
if (!sessionId) {
|
|
160
|
+
console.log(`[CRONMAP] skip: no sessionId in ALS scope (ctxFound=${!!sessionCtx})`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const pushId = await resolvePushId(sessionId);
|
|
164
|
+
if (!pushId) {
|
|
165
|
+
console.log(`[CRONMAP] skip: no pushId available for sessionId=${sessionId} (no session match, no global, no file)`);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
console.log(`[CRONMAP] writing map: jobId=${jobId}, sessionId=${sessionId}, pushId=${pushId.substring(0, 16)}...`);
|
|
169
|
+
await setJobPushId(jobId, {
|
|
170
|
+
pushId,
|
|
171
|
+
sessionId,
|
|
172
|
+
deviceType: sessionCtx?.deviceType,
|
|
173
|
+
source: event.toolName === "exec" ? "exec-cli" : "conversation",
|
|
174
|
+
});
|
|
175
|
+
console.log(`[CRONMAP] map written OK`);
|
|
176
|
+
}
|
|
177
|
+
/** 回退链取 pushId:当前会话 → 全局兜底 → 本地文件首个(保底)。 */
|
|
178
|
+
async function resolvePushId(sessionId) {
|
|
179
|
+
// 1. 同会话
|
|
180
|
+
const session = configManager.getPushId(sessionId);
|
|
181
|
+
if (session)
|
|
182
|
+
return session;
|
|
183
|
+
// 2. 全局(任何会话注册过的)
|
|
184
|
+
const global = configManager.getPushId();
|
|
185
|
+
if (global)
|
|
186
|
+
return global;
|
|
187
|
+
// 3. 文件兜底
|
|
188
|
+
try {
|
|
189
|
+
const all = await getAllPushIds();
|
|
190
|
+
if (all.length > 0)
|
|
191
|
+
return all[0];
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
// ignore
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
/** 判断 exec 命令是否为 cron add(匹配 "openclaw cron add" 或裸 "cron add",排除 list/remove 等)。 */
|
|
199
|
+
function isExecCronAddCommand(command) {
|
|
200
|
+
if (typeof command !== "string")
|
|
201
|
+
return false;
|
|
202
|
+
return /\bcron\s+add\b/.test(command);
|
|
203
|
+
}
|
|
204
|
+
/** 取结果的短预览,用于诊断。 */
|
|
205
|
+
function preview(value) {
|
|
206
|
+
if (value == null)
|
|
207
|
+
return String(value);
|
|
208
|
+
const s = typeof value === "string" ? value : JSON.stringify(value);
|
|
209
|
+
return s.length > 200 ? s.slice(0, 200) + "…" : s;
|
|
210
|
+
}
|
|
211
|
+
/** 防御性地从 cron add 结果中取 job id。
|
|
212
|
+
* 覆盖:裸 job 对象、JSON 字符串、exec 输出文本、
|
|
213
|
+
* {content:[{text}]} / {stdout} / data/result/job 嵌套。 */
|
|
214
|
+
function readJobIdFromResult(result) {
|
|
215
|
+
if (!result)
|
|
216
|
+
return undefined;
|
|
217
|
+
// {content: [{type:"text", text: "..."}]} — exec 工具的输出信封
|
|
218
|
+
if (result && typeof result === "object") {
|
|
219
|
+
const contentArr = result.content;
|
|
220
|
+
if (Array.isArray(contentArr)) {
|
|
221
|
+
for (const item of contentArr) {
|
|
222
|
+
if (item && typeof item === "object") {
|
|
223
|
+
const text = item.text;
|
|
224
|
+
if (typeof text === "string" && text.trim()) {
|
|
225
|
+
const fromContent = readJobIdFromResult(text);
|
|
226
|
+
if (fromContent)
|
|
227
|
+
return fromContent;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// {stdout} — 备选 exec 输出信封
|
|
234
|
+
if (result && typeof result === "object") {
|
|
235
|
+
const stdout = result.stdout;
|
|
236
|
+
if (typeof stdout === "string" && stdout.trim()) {
|
|
237
|
+
const fromStdout = readJobIdFromResult(stdout);
|
|
238
|
+
if (fromStdout)
|
|
239
|
+
return fromStdout;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
let obj = result;
|
|
243
|
+
if (typeof result === "string") {
|
|
244
|
+
try {
|
|
245
|
+
obj = JSON.parse(result);
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
// 纯文本:可能含 stderr 前缀行 + JSON。用正则抓 "id":"..."。
|
|
249
|
+
const m = result.match(/"id"\s*:\s*"([^"]+)"/);
|
|
250
|
+
if (m)
|
|
251
|
+
return m[1];
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (obj && typeof obj === "object") {
|
|
256
|
+
const id = obj.id;
|
|
257
|
+
if (typeof id === "string" && id.trim())
|
|
258
|
+
return id.trim();
|
|
259
|
+
for (const k of ["data", "result", "job"]) {
|
|
260
|
+
const inner = obj[k];
|
|
261
|
+
if (inner && typeof inner === "object") {
|
|
262
|
+
const innerId = inner.id;
|
|
263
|
+
if (typeof innerId === "string" && innerId.trim())
|
|
264
|
+
return innerId.trim();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
// ── Gateway startup: cron state recovery ────────────────────────────────────
|
|
271
|
+
/**
|
|
272
|
+
* Register the gateway_start hook for cron state recovery.
|
|
273
|
+
*
|
|
274
|
+
* On gateway startup, checks .openclaw/cron/ for legacy JSON/JSONL files
|
|
275
|
+
* and migrates them into the SQLite state database:
|
|
276
|
+
* - Reads legacy jobs.json + jobs-state.json → imports into cron_jobs table
|
|
277
|
+
* - Reads legacy runs/*.jsonl → imports into cron_run_logs table
|
|
278
|
+
* - Archives migrated files with .migrated suffix
|
|
279
|
+
*
|
|
280
|
+
* Pattern follows legacy-store-migration.ts and legacy-run-log-migration.ts:
|
|
281
|
+
* check → load → import into SQLite → archive old files.
|
|
282
|
+
*/
|
|
283
|
+
function registerCronRecoveryHook(api) {
|
|
284
|
+
api.on("gateway_start", async (_event, _ctx) => {
|
|
285
|
+
const logTag = "[CRON-RECOVERY-HOOK]";
|
|
286
|
+
const startTime = Date.now();
|
|
287
|
+
logger.log(`${logTag} ═══════════════════════════════════════════`);
|
|
288
|
+
logger.log(`${logTag} gateway_start fired — checking for legacy cron files`);
|
|
289
|
+
logger.log(`${logTag} Timestamp: ${new Date().toISOString()}`);
|
|
290
|
+
logger.log(`${logTag} Plugin registration mode: ${api.registrationMode ?? "unknown"}`);
|
|
291
|
+
let result;
|
|
292
|
+
try {
|
|
293
|
+
result = await recoverCronState();
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
297
|
+
const errStack = err instanceof Error ? err.stack : undefined;
|
|
298
|
+
logger.error(`${logTag} cron state recovery threw: ${errMsg}`);
|
|
299
|
+
if (errStack)
|
|
300
|
+
logger.error(`${logTag} Stack: ${errStack}`);
|
|
301
|
+
// Don't let a recovery failure block gateway startup.
|
|
302
|
+
logger.log(`${logTag} Recovery failed after ${Date.now() - startTime}ms — gateway startup continues`);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const elapsed = Date.now() - startTime;
|
|
306
|
+
if (result.recovered) {
|
|
307
|
+
logger.log(`${logTag} ✅ Migration performed successfully in ${elapsed}ms:` +
|
|
308
|
+
` storeMigrated=${result.storeMigrated}, ` +
|
|
309
|
+
` runLogFilesImported=${result.runLogFilesImported}`);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
logger.log(`${logTag} ℹ️ No legacy cron files migrated in ${elapsed}ms ` +
|
|
313
|
+
`(nothing to migrate or database unavailable)`);
|
|
314
|
+
}
|
|
315
|
+
// Log diagnostics summary
|
|
316
|
+
const warnings = result.diagnostics.filter((d) => d.includes("skipping") || d.includes("locked") || d.includes("unavailable"));
|
|
317
|
+
const errors = result.diagnostics.filter((d) => d.includes("error") || d.includes("failed") || d.includes("Failed"));
|
|
318
|
+
if (warnings.length > 0) {
|
|
319
|
+
logger.warn(`${logTag} ${warnings.length} warning(s) from migration:`);
|
|
320
|
+
for (const w of warnings) {
|
|
321
|
+
logger.warn(`${logTag} ⚠ ${w}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (errors.length > 0) {
|
|
325
|
+
logger.error(`${logTag} ${errors.length} error(s) from migration:`);
|
|
326
|
+
for (const e of errors) {
|
|
327
|
+
logger.error(`${logTag} ✗ ${e}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (warnings.length === 0 && errors.length === 0) {
|
|
331
|
+
logger.log(`${logTag} All diagnostics clean, no warnings or errors`);
|
|
332
|
+
}
|
|
333
|
+
logger.log(`${logTag} ═══════════════════════════════════════════`);
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* 从 sessions_spawn 工具结果中提取 ACP child sessionKey。
|
|
338
|
+
* 兼容三种 result 形态:{status, childSessionKey} 直返、JSON 字符串、
|
|
339
|
+
* {content:[{text: "<json>"}], details:{...}} 工具信封。
|
|
340
|
+
* 仅接受 status="accepted" 且 key 形如 agent:<id>:acp:<uuid> 的结果。
|
|
341
|
+
*/
|
|
342
|
+
function extractAcceptedAcpChildSessionKey(result) {
|
|
343
|
+
const pick = (obj) => {
|
|
344
|
+
if (!obj || typeof obj !== "object")
|
|
345
|
+
return null;
|
|
346
|
+
const record = obj;
|
|
347
|
+
if (record.status !== "accepted")
|
|
348
|
+
return null;
|
|
349
|
+
const key = record.childSessionKey;
|
|
350
|
+
return typeof key === "string" && key.includes(":acp:") ? key : null;
|
|
351
|
+
};
|
|
352
|
+
const direct = pick(result);
|
|
353
|
+
if (direct)
|
|
354
|
+
return direct;
|
|
355
|
+
const envelope = result;
|
|
356
|
+
const fromDetails = pick(envelope?.details);
|
|
357
|
+
if (fromDetails)
|
|
358
|
+
return fromDetails;
|
|
359
|
+
if (Array.isArray(envelope?.content)) {
|
|
360
|
+
for (const item of envelope.content) {
|
|
361
|
+
if (typeof item?.text !== "string")
|
|
362
|
+
continue;
|
|
363
|
+
try {
|
|
364
|
+
const fromText = pick(JSON.parse(item.text));
|
|
365
|
+
if (fromText)
|
|
366
|
+
return fromText;
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
// 非 JSON 文本,忽略
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (typeof result === "string") {
|
|
374
|
+
try {
|
|
375
|
+
return pick(JSON.parse(result));
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
function registerSubagentHooks(api) {
|
|
384
|
+
// subagent_spawned: fires after a subagent run is successfully registered.
|
|
385
|
+
// We increment the expected completion count so that onIdle knows to wait.
|
|
386
|
+
api.on("subagent_spawned", async (_event, ctx) => {
|
|
387
|
+
const requesterSessionKey = ctx?.requesterSessionKey;
|
|
388
|
+
if (!requesterSessionKey)
|
|
389
|
+
return;
|
|
390
|
+
const count = markSubagentSpawned(requesterSessionKey);
|
|
391
|
+
if (count > 0) {
|
|
392
|
+
logger.log(`[XY-SUBAGENT] spawned, requesterSessionKey=${requesterSessionKey.slice(0, 30)}, expected=${count}`);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
// ACP SPAWN TRACKING: openclaw 的 subagent_spawned hook 仅由内嵌 subagent
|
|
396
|
+
// 路径(subagent-spawn.ts)发射;acp-spawn.ts(runtime="acp",如 Claude Code)
|
|
397
|
+
// 不发射 —— 实测 ACP run 仅在结束时经 run registry 触发 subagent_ended,
|
|
398
|
+
// 导致等待态从未建立、父 turn onIdle 直接发 final 结束对话。
|
|
399
|
+
// 因此在 after_tool_call 补记:sessions_spawn 成功且 childSessionKey 为 ACP
|
|
400
|
+
// 形态时递增等待计数。内嵌 subagent 的 childKey 形如 agent:<id>:subagent:<id>,
|
|
401
|
+
// 不命中此分支,仍由 subagent_spawned hook 负责,不会重复计数。
|
|
402
|
+
api.on("after_tool_call", async (event, ctx) => {
|
|
403
|
+
try {
|
|
404
|
+
if (event?.toolName !== "sessions_spawn" || event?.error)
|
|
405
|
+
return;
|
|
406
|
+
const childKey = extractAcceptedAcpChildSessionKey(event?.result);
|
|
407
|
+
if (!childKey)
|
|
408
|
+
return;
|
|
409
|
+
const sessionKey = ctx?.sessionKey;
|
|
410
|
+
if (!sessionKey)
|
|
411
|
+
return;
|
|
412
|
+
const count = markSubagentSpawned(sessionKey);
|
|
413
|
+
if (count > 0) {
|
|
414
|
+
logger.log(`[XY-SUBAGENT] ACP spawned, childSessionKey=${childKey.slice(0, 40)}, expected=${count}`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
catch (err) {
|
|
418
|
+
logger.error(`[XY-SUBAGENT] Error tracking ACP spawn:`, err);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
// subagent_ended: fires when a subagent run terminates (complete/error/killed).
|
|
422
|
+
// This is the PRIMARY delivery tracking mechanism. When all expected
|
|
423
|
+
// subagents have ended and parent has settled, we finalize the A2A session.
|
|
424
|
+
api.on("subagent_ended", async (event, ctx) => {
|
|
425
|
+
try {
|
|
426
|
+
const requesterSessionKey = ctx?.requesterSessionKey;
|
|
427
|
+
if (!requesterSessionKey) {
|
|
428
|
+
logger.log(`[XY-SUBAGENT-END] no requesterSessionKey in ctx`);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
const transition = markSubagentEnded(requesterSessionKey);
|
|
432
|
+
logger.log(`[XY-SUBAGENT-END] ended, targetSessionKey=${event?.targetSessionKey?.slice(0, 30)}, outcome=${event?.outcome}, complete=${transition?.isComplete ?? false}, shouldFinalize=${transition?.shouldFinalize ?? false}, transition=${!!transition}`);
|
|
433
|
+
if (transition?.shouldFinalize) {
|
|
434
|
+
logger.log(`[XY-SUBAGENT-END] Starting finalization...`);
|
|
435
|
+
// Grace: announce 投递的 sendText 与 subagent_ended hook 并发到达
|
|
436
|
+
// (实测 sendText 可能先于 hook 约 1s,也可能晚于 hook;长文本还会
|
|
437
|
+
// 被 textChunkLimit 分片成多次 sendText)。捕获窗口直到
|
|
438
|
+
// finalDeliveryStarted 才关闭,此处的等待直接扩大迟到来片的入窗机会。
|
|
439
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
440
|
+
// 最终交付由对话管理层统一负责(含 config 解析、final 帧、清理)
|
|
441
|
+
await deliverSubagentFinalResult({
|
|
442
|
+
state: transition.state,
|
|
443
|
+
reason: "all-subagents-ended-after-parent-settled",
|
|
444
|
+
});
|
|
445
|
+
logger.log(`[XY-SUBAGENT-END] Finalized A2A session after all subagents ended`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
catch (err) {
|
|
449
|
+
logger.error(`[XY-SUBAGENT-END] Error in subagent_ended hook:`, err);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
function registerFullHooks(api) {
|
|
454
|
+
// SUBAGENT HOOKS: track subagent spawn/end lifecycle for session keep-alive
|
|
455
|
+
registerSubagentHooks(api);
|
|
456
|
+
// CRON AGGREGATION: 通过 agent 事件总线感知 cron isolated run 结束。
|
|
457
|
+
// 注意:agent_end 插件 hook 只在 dispatch-from-config 路径触发,cron
|
|
458
|
+
// isolated run 不会触发它;embedded run 的 lifecycle 事件才是可靠信号。
|
|
459
|
+
// phase=end/error 后到达的 sendText 即为 announce 最终结果(放行)。
|
|
460
|
+
api.agent.events.registerAgentEventSubscription({
|
|
461
|
+
id: "xy-cron-turn-tracker",
|
|
462
|
+
description: "Track cron isolated run completion for sendText aggregation",
|
|
463
|
+
streams: ["lifecycle"],
|
|
464
|
+
handle: (event) => {
|
|
465
|
+
try {
|
|
466
|
+
const phase = event?.data?.phase;
|
|
467
|
+
// 仅 phase=end 是 run 级终态信号;phase=error 可能是单次模型调用
|
|
468
|
+
// 失败(后续还有重试/start),不能据此放行 announce。
|
|
469
|
+
// 真正失败的 run(无 end)由 120s 安全超时兜底 flush 缓冲文本。
|
|
470
|
+
if (phase !== "end")
|
|
471
|
+
return;
|
|
472
|
+
const sessionKey = event?.sessionKey ?? "";
|
|
473
|
+
// 从 sessionKey(agent:<id>:cron:<jobId>:run:<ts>)解析 jobId,只结束
|
|
474
|
+
// 该 job 的 turn;isCronActive(jobId) 作为无 cron 前缀版本的兜底(按
|
|
475
|
+
// jobId 精确判断,普通对话的 lifecycle end 不会命中)。
|
|
476
|
+
const cronJobId = parseCronJobIdFromSessionKey(sessionKey);
|
|
477
|
+
if (sessionKey.includes("cron:") || sessionKey.startsWith("cron:") || isCronActive(cronJobId)) {
|
|
478
|
+
logger.log(`[XY-CRON] Cron run lifecycle end, sessionKey=${sessionKey || "unknown"}, jobId=${cronJobId ?? "-"}`);
|
|
479
|
+
notifyCronAgentEnd(cronJobId);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
catch (err) {
|
|
483
|
+
logger.error(`[XY-CRON] Error in cron lifecycle subscription:`, err);
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
// SKILL RETRIEVER HOOK: before_prompt_build hook
|
|
488
|
+
const pluginConfig = api.pluginConfig || {};
|
|
489
|
+
const skillRetrieverConfig = normalizeToolRetrieverConfig({
|
|
490
|
+
enabled: pluginConfig.skillRetrieverEnabled ?? true,
|
|
491
|
+
maxTools: pluginConfig.skillRetrieverMaxTools ?? 6,
|
|
492
|
+
includeUninstalledOnly: true,
|
|
493
|
+
envFilePath: "~/.openclaw/.xiaoyienv",
|
|
494
|
+
timeoutMs: pluginConfig.skillRetrieverTimeoutMs ?? 10000,
|
|
495
|
+
});
|
|
496
|
+
const beforePromptBuildHandler = createBeforePromptBuildHandler(skillRetrieverConfig);
|
|
497
|
+
api.on("before_prompt_build", async (event, ctx) => {
|
|
498
|
+
logger.log(`[BEFORE_PROMPT_BUILD] hook fired, sessionKey=${ctx.sessionKey || "undefined"}, sessionId=${ctx.sessionId || "undefined"}`);
|
|
499
|
+
return beforePromptBuildHandler(event, ctx);
|
|
500
|
+
});
|
|
501
|
+
registerSelfEvolutionToolResultNudge(api);
|
|
502
|
+
}
|
|
503
|
+
const plugin = definePluginEntry({
|
|
10
504
|
id: "xiaoyi-channel",
|
|
11
505
|
name: "Xiaoyi Channel",
|
|
12
506
|
description: "Xiaoyi channel plugin - Xiaoyi A2A protocol integration",
|
|
13
|
-
configSchema: emptyPluginConfigSchema(),
|
|
14
507
|
register(api) {
|
|
15
|
-
|
|
508
|
+
// Always register the provider so wrapStreamFn/prepareExtraParams work
|
|
509
|
+
// in ALL registration modes (not just "full").
|
|
510
|
+
api.registerProvider(xiaoyiProvider);
|
|
511
|
+
// Register the compaction provider so openclaw's safeguard hook uses
|
|
512
|
+
// our summarization path (which injects x-hag-trace-id) instead of the
|
|
513
|
+
// built-in LLM path that bypasses wrapStreamFn.
|
|
514
|
+
api.registerCompactionProvider(xiaoyiCompactionProvider);
|
|
515
|
+
if (api.registrationMode === "cli-metadata") {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (api.registrationMode === "tool-discovery") {
|
|
519
|
+
registerFullHooks(api);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
// Register channel plugin and set runtime
|
|
16
523
|
api.registerChannel({ plugin: xyPlugin });
|
|
524
|
+
setXYRuntime(api.runtime);
|
|
525
|
+
if (api.registrationMode === "discovery") {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (api.registrationMode === "full") {
|
|
529
|
+
registerFullHooks(api);
|
|
530
|
+
// CSPL sentinel hook: before_tool_call + after_tool_call security scanning
|
|
531
|
+
registerSentinelHook(api);
|
|
532
|
+
// CSPL skill scope hook: before_install security scanning
|
|
533
|
+
registerSkillScopeHook(api);
|
|
534
|
+
// Cron detection hook: marks toolCallIds from cron sessions
|
|
535
|
+
registerCronDetectionHook(api);
|
|
536
|
+
// CLI exec hook: intercepts built-in exec for HarmonyOS CLI skill tools
|
|
537
|
+
registerCLIHook(api);
|
|
538
|
+
// Cron recovery hook: prunes stale cron-push-map and pushData on gateway startup
|
|
539
|
+
registerCronRecoveryHook(api);
|
|
540
|
+
// Skills diagnostic hook: log skill usage (detected via SKILL.md reads)
|
|
541
|
+
registerSkillsDiagnosticHook(api);
|
|
542
|
+
}
|
|
17
543
|
},
|
|
18
|
-
};
|
|
544
|
+
});
|
|
19
545
|
export default plugin;
|
|
20
|
-
// Also export the plugin directly for testing
|
|
21
|
-
export { xyPlugin };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type BindingTargetKind } from "openclaw/plugin-sdk/conversation-runtime";
|
|
2
|
+
type XyBindingTargetKind = "subagent" | "acp";
|
|
3
|
+
type XyAcpBindingRecord = {
|
|
4
|
+
accountId: string;
|
|
5
|
+
conversationId: string;
|
|
6
|
+
parentConversationId?: string;
|
|
7
|
+
deliveryTo?: string;
|
|
8
|
+
targetKind: XyBindingTargetKind;
|
|
9
|
+
targetSessionKey: string;
|
|
10
|
+
agentId?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
boundBy?: string;
|
|
13
|
+
boundAt: number;
|
|
14
|
+
lastActivityAt: number;
|
|
15
|
+
};
|
|
16
|
+
type XyAcpBindingManager = {
|
|
17
|
+
accountId: string;
|
|
18
|
+
getByConversationId: (conversationId: string) => XyAcpBindingRecord | undefined;
|
|
19
|
+
listBySessionKey: (targetSessionKey: string) => XyAcpBindingRecord[];
|
|
20
|
+
bindConversation: (params: {
|
|
21
|
+
conversationId: string;
|
|
22
|
+
parentConversationId?: string;
|
|
23
|
+
targetKind: BindingTargetKind;
|
|
24
|
+
targetSessionKey: string;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
}) => XyAcpBindingRecord | null;
|
|
27
|
+
touchConversation: (conversationId: string, at?: number) => XyAcpBindingRecord | null;
|
|
28
|
+
unbindConversation: (conversationId: string) => XyAcpBindingRecord | null;
|
|
29
|
+
unbindBySessionKey: (targetSessionKey: string) => XyAcpBindingRecord[];
|
|
30
|
+
stop: () => void;
|
|
31
|
+
};
|
|
32
|
+
export declare function createXyAcpBindingManager(params: {
|
|
33
|
+
accountId?: string;
|
|
34
|
+
cfg: any;
|
|
35
|
+
}): XyAcpBindingManager;
|
|
36
|
+
export declare function getXyAcpBindingManager(accountId?: string): XyAcpBindingManager | null;
|
|
37
|
+
export {};
|