@ynhcj/xiaoyi-channel 0.0.26-next → 0.0.26-test20260606
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 -13
- package/dist/index.js +403 -55
- 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 +379 -162
- package/dist/src/channel.js +84 -22
- package/dist/src/client.d.ts +4 -3
- package/dist/src/client.js +32 -43
- package/dist/src/compaction-provider.d.ts +50 -0
- package/dist/src/compaction-provider.js +202 -0
- package/dist/src/cron-command.d.ts +17 -0
- package/dist/src/cron-command.js +55 -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 +6 -0
- package/dist/src/cspl/call-api.js +45 -42
- package/dist/src/cspl/call_api.d.ts +8 -0
- package/dist/src/cspl/call_api.js +152 -0
- package/dist/src/cspl/config.d.ts +4 -8
- package/dist/src/cspl/config.js +113 -44
- package/dist/src/cspl/configs.json +10 -0
- package/dist/src/cspl/constants.d.ts +83 -21
- package/dist/src/cspl/constants.js +67 -16
- package/dist/src/cspl/middleware.d.ts +8 -0
- package/dist/src/cspl/middleware.js +90 -0
- package/dist/src/cspl/sentinel_hook.d.ts +2 -0
- package/dist/src/cspl/sentinel_hook.js +108 -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 +37 -1
- package/dist/src/cspl/utils.js +423 -15
- package/dist/src/file-download.d.ts +1 -0
- package/dist/src/file-download.js +3 -4
- package/dist/src/file-upload.d.ts +5 -0
- package/dist/src/file-upload.js +171 -31
- package/dist/src/formatter.d.ts +81 -1
- package/dist/src/formatter.js +305 -72
- package/dist/src/heartbeat.js +4 -3
- package/dist/src/log-reporter/config-loader.d.ts +11 -0
- package/dist/src/log-reporter/config-loader.js +68 -0
- package/dist/src/log-reporter/cursor-store.d.ts +5 -0
- package/dist/src/log-reporter/cursor-store.js +26 -0
- package/dist/src/log-reporter/index.d.ts +10 -0
- package/dist/src/log-reporter/index.js +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 +178 -61
- package/dist/src/outbound.d.ts +7 -0
- package/dist/src/outbound.js +89 -48
- package/dist/src/parser.d.ts +26 -1
- package/dist/src/parser.js +113 -0
- package/dist/src/provider.d.ts +3 -0
- package/dist/src/provider.js +784 -0
- package/dist/src/push.d.ts +11 -1
- package/dist/src/push.js +102 -38
- package/dist/src/reply-dispatcher.d.ts +12 -1
- package/dist/src/reply-dispatcher.js +373 -169
- 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 +203 -0
- package/dist/src/skill-retriever/tool-search.d.ts +19 -0
- package/dist/src/skill-retriever/tool-search.js +186 -0
- package/dist/src/skill-retriever/types.d.ts +37 -0
- package/dist/src/skill-retriever/types.js +1 -0
- package/dist/src/steer-injector.js +1 -1
- 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 +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 +9 -10
- 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 +20 -1
- package/dist/src/tools/call-phone-tool.js +15 -35
- 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 +39 -1
- package/dist/src/tools/create-alarm-tool.js +14 -30
- package/dist/src/tools/create-all-tools.d.ts +16 -0
- package/dist/src/tools/create-all-tools.js +62 -0
- package/dist/src/tools/delete-alarm-tool.d.ts +15 -1
- package/dist/src/tools/delete-alarm-tool.js +10 -14
- 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 +65 -0
- package/dist/src/tools/display-a2ui-card-tool.d.ts +2 -0
- package/dist/src/tools/display-a2ui-card-tool.js +85 -0
- package/dist/src/tools/find-pc-devices-tool.d.ts +6 -0
- package/dist/src/tools/find-pc-devices-tool.js +95 -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 +29 -2
- package/dist/src/tools/image-reading-tool.js +44 -126
- package/dist/src/tools/invoke.d.ts +88 -0
- package/dist/src/tools/invoke.js +1209 -0
- package/dist/src/tools/location-tool.d.ts +11 -1
- package/dist/src/tools/location-tool.js +12 -10
- 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 +47 -1
- package/dist/src/tools/modify-alarm-tool.js +37 -38
- package/dist/src/tools/modify-note-tool.d.ts +20 -1
- package/dist/src/tools/modify-note-tool.js +9 -10
- package/dist/src/tools/note-tool.d.ts +20 -1
- package/dist/src/tools/note-tool.js +9 -10
- 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 +34 -1
- package/dist/src/tools/search-alarm-tool.js +15 -23
- package/dist/src/tools/search-calendar-tool.d.ts +24 -1
- package/dist/src/tools/search-calendar-tool.js +11 -10
- package/dist/src/tools/search-contact-tool.d.ts +16 -1
- package/dist/src/tools/search-contact-tool.js +9 -10
- 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 +16 -1
- package/dist/src/tools/search-file-tool.js +14 -17
- package/dist/src/tools/search-message-tool.d.ts +16 -1
- package/dist/src/tools/search-message-tool.js +9 -9
- package/dist/src/tools/search-note-tool.d.ts +16 -1
- package/dist/src/tools/search-note-tool.js +9 -10
- package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -1
- package/dist/src/tools/search-photo-gallery-tool.js +13 -14
- package/dist/src/tools/send-command-to-car-tool.d.ts +5 -0
- package/dist/src/tools/send-command-to-car-tool.js +85 -0
- 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 +135 -0
- package/dist/src/tools/send-file-to-user-tool.d.ts +20 -1
- package/dist/src/tools/send-file-to-user-tool.js +48 -22
- package/dist/src/tools/send-html-card-tool.d.ts +25 -0
- package/dist/src/tools/send-html-card-tool.js +111 -0
- package/dist/src/tools/send-message-tool.d.ts +20 -1
- package/dist/src/tools/send-message-tool.js +8 -9
- package/dist/src/tools/session-helper.d.ts +24 -0
- package/dist/src/tools/session-helper.js +45 -0
- package/dist/src/tools/session-manager.d.ts +47 -28
- package/dist/src/tools/session-manager.js +175 -87
- 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 +20 -1
- package/dist/src/tools/upload-file-tool.js +17 -17
- package/dist/src/tools/upload-photo-tool.d.ts +20 -1
- package/dist/src/tools/upload-photo-tool.js +15 -16
- 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 +20 -1
- package/dist/src/tools/xiaoyi-collection-tool.js +51 -16
- 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 +24 -11
- package/dist/src/trigger-handler.js +5 -9
- package/dist/src/types.d.ts +25 -1
- 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 +131 -0
- package/dist/src/utils/logger.d.ts +8 -0
- package/dist/src/utils/logger.js +128 -18
- package/dist/src/utils/pushdata-manager.js +1 -5
- package/dist/src/utils/pushid-manager.js +1 -2
- 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 +7 -1
- package/dist/src/websocket.js +370 -52
- package/dist/src/xy-session-store.d.ts +79 -0
- package/dist/src/xy-session-store.js +153 -0
- package/openclaw.plugin.json +26 -0
- package/package.json +9 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
* Xiaoyi Channel Plugin Entry Point.
|
|
4
|
-
* Exports the plugin for OpenClaw to load.
|
|
5
|
-
* Located at root level following feishu pattern for proper plugin registration.
|
|
6
|
-
*/
|
|
7
|
-
declare const plugin: {
|
|
8
|
-
id: string;
|
|
9
|
-
name: string;
|
|
10
|
-
description: string;
|
|
11
|
-
configSchema: import("openclaw/plugin-sdk").OpenClawPluginConfigSchema;
|
|
12
|
-
register(api: OpenClawPluginApi): void;
|
|
13
|
-
};
|
|
1
|
+
import { type OpenClawPluginDefinition } from "openclaw/plugin-sdk/core";
|
|
2
|
+
declare const plugin: OpenClawPluginDefinition;
|
|
14
3
|
export default plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,67 +1,415 @@
|
|
|
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";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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, getCachedXYConfig, } from "./src/subagent-wait-state.js";
|
|
19
|
+
import { logger } from "./src/utils/logger.js";
|
|
9
20
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
21
|
+
* Parse a file path string to detect if it refers to a SKILL.md file within
|
|
22
|
+
* a skills directory. Returns the skill name (parent directory) if so.
|
|
23
|
+
*
|
|
24
|
+
* Matches paths like:
|
|
25
|
+
* ~/.openclaw/workspace/skills/my-skill/SKILL.md
|
|
26
|
+
* /home/user/core_skills/my-skill/SKILL.md
|
|
27
|
+
* skills/my-skill/SKILL.md
|
|
13
28
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
function extractSkillNameFromPath(filePath) {
|
|
30
|
+
if (typeof filePath !== "string" || !filePath)
|
|
31
|
+
return null;
|
|
32
|
+
// Normalize common path prefixes
|
|
33
|
+
const normalized = filePath.replace(/^~\//, "/home/").replace(/\\/g, "/");
|
|
34
|
+
// Match: .../skills/<skillName>/SKILL.md or .../skills/<skillName>/...
|
|
35
|
+
// Also match: .../core_skills/<skillName>/SKILL.md
|
|
36
|
+
const match = normalized.match(/\/(?:core_)?skills\/([^/]+)\/SKILL\.md$/i);
|
|
37
|
+
return match ? match[1] : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Register the skills diagnostic event listener via after_tool_call hook.
|
|
41
|
+
*
|
|
42
|
+
* When openclaw fires a `skill.used` diagnostic event, the skill's SKILL.md
|
|
43
|
+
* is typically read by the model first. We detect SKILL.md reads through
|
|
44
|
+
* the `after_tool_call` hook and write the skill name to the skills log.
|
|
45
|
+
*/
|
|
46
|
+
function registerSkillsDiagnosticHook(api) {
|
|
47
|
+
// Tool name → skill name mapping for direct tool-based skill usage logging
|
|
48
|
+
const TOOL_SKILL_MAP = {
|
|
49
|
+
get_user_location: "GetCurrentLocation",
|
|
50
|
+
get_calendar_tool_schema: "Schedule",
|
|
51
|
+
get_note_tool_schema: "memorandum",
|
|
52
|
+
get_photo_tool_schema: "gallery",
|
|
53
|
+
get_contact_tool_schema: "contact",
|
|
54
|
+
get_device_file_tool_schema: "file",
|
|
55
|
+
get_alarm_tool_schema: "clock",
|
|
56
|
+
message: "message",
|
|
57
|
+
get_phone_tool_schema: "phone",
|
|
58
|
+
get_collection_tool_schema: "xiaoyi-collection",
|
|
59
|
+
image_reading: "xiaoyi-image-understanding"
|
|
60
|
+
};
|
|
61
|
+
// Log skill usage for known device tools on before_tool_call
|
|
62
|
+
api.on("before_tool_call", async (event, _ctx) => {
|
|
63
|
+
const skillName = TOOL_SKILL_MAP[event.toolName];
|
|
64
|
+
if (skillName) {
|
|
65
|
+
writeSkillUsage(skillName);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
// Detect SKILL.md reads on after_tool_call (original behavior)
|
|
69
|
+
api.on("after_tool_call", async (event, _ctx) => {
|
|
70
|
+
if (event.toolName === "read") {
|
|
71
|
+
const skillName = extractSkillNameFromPath(event.params?.path);
|
|
72
|
+
if (skillName) {
|
|
73
|
+
writeSkillUsage(skillName);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Register the cron detection hook.
|
|
80
|
+
*
|
|
81
|
+
* When openclaw's cron runner triggers a tool call, the sessionKey has the
|
|
82
|
+
* format "cron:<jobId>". We use this to mark the toolCallId in a global Map
|
|
83
|
+
* so that sendCommand() can route the command through the push channel
|
|
84
|
+
* instead of the (non-existent) WebSocket session.
|
|
85
|
+
*/
|
|
86
|
+
function registerCronDetectionHook(api) {
|
|
87
|
+
api.on("before_tool_call", async (event, ctx) => {
|
|
88
|
+
// sessionKey 前缀依赖 openclaw 版本行为,不一定可靠;
|
|
89
|
+
// isCronActive() 由 provider.ts 根据消息内容 [cron:...] 设置,更可靠。
|
|
90
|
+
if ((ctx.sessionKey?.startsWith("cron:") || isCronActive()) && event.toolCallId) {
|
|
91
|
+
markCronToolCall(event.toolCallId);
|
|
92
|
+
// 存储 runId,供 call_device_tool 在 ALS 缺失时构造合成 SessionContext
|
|
93
|
+
if (event.runId) {
|
|
94
|
+
setCronToolRunInfo(event.toolCallId, event.runId);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
api.on("after_tool_call", async (event, ctx) => {
|
|
99
|
+
if (event.toolCallId) {
|
|
100
|
+
clearCronToolCall(event.toolCallId);
|
|
101
|
+
clearCronToolRunInfo(event.toolCallId);
|
|
102
|
+
}
|
|
103
|
+
// 捕获对话创建的 cron job:agent 调 cron(add) 后,从 result 拿 jobId,
|
|
104
|
+
// 配合当前会话的 pushId,写入 jobId↔pushId 映射,供 fire 时反查设备。
|
|
105
|
+
await captureCronAddMapping(event, ctx).catch((err) => {
|
|
106
|
+
// 捕获失败不影响工具结果
|
|
107
|
+
console.error("[xy] captureCronAddMapping failed:", err);
|
|
26
108
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** 从 cron add 工具结果中提取 jobId 并写入 pushId 映射。 */
|
|
112
|
+
async function captureCronAddMapping(event, ctx) {
|
|
113
|
+
// 两条创建路径都要捕获:
|
|
114
|
+
// 1) cron agent 工具:toolName==="cron", params.action==="add"
|
|
115
|
+
// 2) exec 跑 CLI:toolName==="exec", params.command 含 "cron add"
|
|
116
|
+
// (agent 实际用的是这条:openclaw cron add --name ... --cron ... --message ...)
|
|
117
|
+
const isCronAddTool = event.toolName === "cron" &&
|
|
118
|
+
(event.params?.action === "add" || event.params?.action === "create");
|
|
119
|
+
const isExecCronAdd = event.toolName === "exec" && isExecCronAddCommand(event.params?.command);
|
|
120
|
+
if (!isCronAddTool && !isExecCronAdd)
|
|
121
|
+
return;
|
|
122
|
+
console.log(`[CRONMAP] after_tool_call path=${event.toolName}, resultType=${typeof event.result}`);
|
|
123
|
+
const jobId = readJobIdFromResult(event.result);
|
|
124
|
+
if (!jobId) {
|
|
125
|
+
console.log(`[CRONMAP] skip: could not extract jobId. preview=${preview(event.result)}`);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
console.log(`[CRONMAP] extracted jobId=${jobId}`);
|
|
129
|
+
const sessionCtx = getCurrentSessionContext();
|
|
130
|
+
const sessionId = sessionCtx?.sessionId;
|
|
131
|
+
if (!sessionId) {
|
|
132
|
+
console.log(`[CRONMAP] skip: no sessionId in ALS scope (ctxFound=${!!sessionCtx})`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const pushId = await resolvePushId(sessionId);
|
|
136
|
+
if (!pushId) {
|
|
137
|
+
console.log(`[CRONMAP] skip: no pushId available for sessionId=${sessionId} (no session match, no global, no file)`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
console.log(`[CRONMAP] writing map: jobId=${jobId}, sessionId=${sessionId}, pushId=${pushId.substring(0, 16)}...`);
|
|
141
|
+
await setJobPushId(jobId, {
|
|
142
|
+
pushId,
|
|
143
|
+
sessionId,
|
|
144
|
+
deviceType: sessionCtx?.deviceType,
|
|
145
|
+
source: event.toolName === "exec" ? "exec-cli" : "conversation",
|
|
146
|
+
});
|
|
147
|
+
console.log(`[CRONMAP] map written OK`);
|
|
148
|
+
}
|
|
149
|
+
/** 回退链取 pushId:当前会话 → 全局兜底 → 本地文件首个(保底)。 */
|
|
150
|
+
async function resolvePushId(sessionId) {
|
|
151
|
+
// 1. 同会话
|
|
152
|
+
const session = configManager.getPushId(sessionId);
|
|
153
|
+
if (session)
|
|
154
|
+
return session;
|
|
155
|
+
// 2. 全局(任何会话注册过的)
|
|
156
|
+
const global = configManager.getPushId();
|
|
157
|
+
if (global)
|
|
158
|
+
return global;
|
|
159
|
+
// 3. 文件兜底
|
|
160
|
+
try {
|
|
161
|
+
const all = await getAllPushIds();
|
|
162
|
+
if (all.length > 0)
|
|
163
|
+
return all[0];
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// ignore
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
/** 判断 exec 命令是否为 cron add(匹配 "openclaw cron add" 或裸 "cron add",排除 list/remove 等)。 */
|
|
171
|
+
function isExecCronAddCommand(command) {
|
|
172
|
+
if (typeof command !== "string")
|
|
173
|
+
return false;
|
|
174
|
+
return /\bcron\s+add\b/.test(command);
|
|
175
|
+
}
|
|
176
|
+
/** 取结果的短预览,用于诊断。 */
|
|
177
|
+
function preview(value) {
|
|
178
|
+
if (value == null)
|
|
179
|
+
return String(value);
|
|
180
|
+
const s = typeof value === "string" ? value : JSON.stringify(value);
|
|
181
|
+
return s.length > 200 ? s.slice(0, 200) + "…" : s;
|
|
182
|
+
}
|
|
183
|
+
/** 防御性地从 cron add 结果中取 job id。
|
|
184
|
+
* 覆盖:裸 job 对象、JSON 字符串、exec 输出文本、
|
|
185
|
+
* {content:[{text}]} / {stdout} / data/result/job 嵌套。 */
|
|
186
|
+
function readJobIdFromResult(result) {
|
|
187
|
+
if (!result)
|
|
188
|
+
return undefined;
|
|
189
|
+
// {content: [{type:"text", text: "..."}]} — exec 工具的输出信封
|
|
190
|
+
if (result && typeof result === "object") {
|
|
191
|
+
const contentArr = result.content;
|
|
192
|
+
if (Array.isArray(contentArr)) {
|
|
193
|
+
for (const item of contentArr) {
|
|
194
|
+
if (item && typeof item === "object") {
|
|
195
|
+
const text = item.text;
|
|
196
|
+
if (typeof text === "string" && text.trim()) {
|
|
197
|
+
const fromContent = readJobIdFromResult(text);
|
|
198
|
+
if (fromContent)
|
|
199
|
+
return fromContent;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// {stdout} — 备选 exec 输出信封
|
|
206
|
+
if (result && typeof result === "object") {
|
|
207
|
+
const stdout = result.stdout;
|
|
208
|
+
if (typeof stdout === "string" && stdout.trim()) {
|
|
209
|
+
const fromStdout = readJobIdFromResult(stdout);
|
|
210
|
+
if (fromStdout)
|
|
211
|
+
return fromStdout;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
let obj = result;
|
|
215
|
+
if (typeof result === "string") {
|
|
216
|
+
try {
|
|
217
|
+
obj = JSON.parse(result);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
// 纯文本:可能含 stderr 前缀行 + JSON。用正则抓 "id":"..."。
|
|
221
|
+
const m = result.match(/"id"\s*:\s*"([^"]+)"/);
|
|
222
|
+
if (m)
|
|
223
|
+
return m[1];
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (obj && typeof obj === "object") {
|
|
228
|
+
const id = obj.id;
|
|
229
|
+
if (typeof id === "string" && id.trim())
|
|
230
|
+
return id.trim();
|
|
231
|
+
for (const k of ["data", "result", "job"]) {
|
|
232
|
+
const inner = obj[k];
|
|
233
|
+
if (inner && typeof inner === "object") {
|
|
234
|
+
const innerId = inner.id;
|
|
235
|
+
if (typeof innerId === "string" && innerId.trim())
|
|
236
|
+
return innerId.trim();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
// ── Gateway startup: cron state recovery ────────────────────────────────────
|
|
243
|
+
/**
|
|
244
|
+
* Register the gateway_start hook for cron state recovery.
|
|
245
|
+
*
|
|
246
|
+
* On gateway startup, checks .openclaw/cron/ for legacy JSON/JSONL files
|
|
247
|
+
* and migrates them into the SQLite state database:
|
|
248
|
+
* - Reads legacy jobs.json + jobs-state.json → imports into cron_jobs table
|
|
249
|
+
* - Reads legacy runs/*.jsonl → imports into cron_run_logs table
|
|
250
|
+
* - Archives migrated files with .migrated suffix
|
|
251
|
+
*
|
|
252
|
+
* Pattern follows legacy-store-migration.ts and legacy-run-log-migration.ts:
|
|
253
|
+
* check → load → import into SQLite → archive old files.
|
|
254
|
+
*/
|
|
255
|
+
function registerCronRecoveryHook(api) {
|
|
256
|
+
api.on("gateway_start", async (_event, _ctx) => {
|
|
257
|
+
const logTag = "[CRON-RECOVERY-HOOK]";
|
|
258
|
+
const startTime = Date.now();
|
|
259
|
+
logger.log(`${logTag} ═══════════════════════════════════════════`);
|
|
260
|
+
logger.log(`${logTag} gateway_start fired — checking for legacy cron files`);
|
|
261
|
+
logger.log(`${logTag} Timestamp: ${new Date().toISOString()}`);
|
|
262
|
+
logger.log(`${logTag} Plugin registration mode: ${api.registrationMode ?? "unknown"}`);
|
|
263
|
+
let result;
|
|
264
|
+
try {
|
|
265
|
+
result = await recoverCronState();
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
269
|
+
const errStack = err instanceof Error ? err.stack : undefined;
|
|
270
|
+
logger.error(`${logTag} cron state recovery threw: ${errMsg}`);
|
|
271
|
+
if (errStack)
|
|
272
|
+
logger.error(`${logTag} Stack: ${errStack}`);
|
|
273
|
+
// Don't let a recovery failure block gateway startup.
|
|
274
|
+
logger.log(`${logTag} Recovery failed after ${Date.now() - startTime}ms — gateway startup continues`);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const elapsed = Date.now() - startTime;
|
|
278
|
+
if (result.recovered) {
|
|
279
|
+
logger.log(`${logTag} ✅ Migration performed successfully in ${elapsed}ms:` +
|
|
280
|
+
` storeMigrated=${result.storeMigrated}, ` +
|
|
281
|
+
` runLogFilesImported=${result.runLogFilesImported}`);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
logger.log(`${logTag} ℹ️ No legacy cron files migrated in ${elapsed}ms ` +
|
|
285
|
+
`(nothing to migrate or database unavailable)`);
|
|
286
|
+
}
|
|
287
|
+
// Log diagnostics summary
|
|
288
|
+
const warnings = result.diagnostics.filter((d) => d.includes("skipping") || d.includes("locked") || d.includes("unavailable"));
|
|
289
|
+
const errors = result.diagnostics.filter((d) => d.includes("error") || d.includes("failed") || d.includes("Failed"));
|
|
290
|
+
if (warnings.length > 0) {
|
|
291
|
+
logger.warn(`${logTag} ${warnings.length} warning(s) from migration:`);
|
|
292
|
+
for (const w of warnings) {
|
|
293
|
+
logger.warn(`${logTag} ⚠ ${w}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (errors.length > 0) {
|
|
297
|
+
logger.error(`${logTag} ${errors.length} error(s) from migration:`);
|
|
298
|
+
for (const e of errors) {
|
|
299
|
+
logger.error(`${logTag} ✗ ${e}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (warnings.length === 0 && errors.length === 0) {
|
|
303
|
+
logger.log(`${logTag} All diagnostics clean, no warnings or errors`);
|
|
304
|
+
}
|
|
305
|
+
logger.log(`${logTag} ═══════════════════════════════════════════`);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
function registerSubagentHooks(api) {
|
|
309
|
+
// subagent_spawned: fires after a subagent run is successfully registered.
|
|
310
|
+
// We increment the expected completion count so that onIdle knows to wait.
|
|
311
|
+
api.on("subagent_spawned", async (_event, ctx) => {
|
|
312
|
+
const requesterSessionKey = ctx?.requesterSessionKey;
|
|
313
|
+
if (!requesterSessionKey)
|
|
314
|
+
return;
|
|
315
|
+
const count = markSubagentSpawned(requesterSessionKey);
|
|
316
|
+
if (count > 0) {
|
|
317
|
+
logger.log(`[XY-SUBAGENT] spawned, requesterSessionKey=${requesterSessionKey.slice(0, 30)}, expected=${count}`);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
// subagent_ended: fires when a subagent run terminates (complete/error/killed).
|
|
321
|
+
// This is the PRIMARY delivery tracking mechanism. When all expected
|
|
322
|
+
// subagents have ended and parent has settled, we finalize the A2A session.
|
|
323
|
+
api.on("subagent_ended", async (event, ctx) => {
|
|
324
|
+
try {
|
|
325
|
+
const requesterSessionKey = ctx?.requesterSessionKey;
|
|
326
|
+
if (!requesterSessionKey) {
|
|
327
|
+
logger.log(`[XY-SUBAGENT-END] no requesterSessionKey in ctx`);
|
|
31
328
|
return;
|
|
32
329
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
330
|
+
const transition = markSubagentEnded(requesterSessionKey);
|
|
331
|
+
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}`);
|
|
332
|
+
if (transition?.shouldFinalize) {
|
|
333
|
+
logger.log(`[XY-SUBAGENT-END] Starting finalization...`);
|
|
334
|
+
const config = getCachedXYConfig();
|
|
335
|
+
if (!config) {
|
|
336
|
+
logger.error(`[XY-SUBAGENT-END] No cached XY config, cannot deliver final result`);
|
|
38
337
|
return;
|
|
39
338
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (finalJson.length > MAX_TEXT_LENGTH) {
|
|
49
|
-
const diff = finalJson.length - MAX_TEXT_LENGTH;
|
|
50
|
-
const { text: trimmed } = validateAndTruncateText(originText, MAX_TEXT_LENGTH - diff);
|
|
51
|
-
questionText.output[0].content = trimmed;
|
|
52
|
-
finalJson = JSON.stringify(questionText);
|
|
53
|
-
}
|
|
54
|
-
const response = await callCsplApi(finalJson, api.config);
|
|
55
|
-
const result = parseSecurityResult(response);
|
|
56
|
-
console.log(`[CSPL] Security result: status=${result.status}`);
|
|
57
|
-
if (result.status === "REJECT") {
|
|
58
|
-
await tryInjectSteer(ctx.sessionKey, STEER_ABORT_MESSAGE);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
api.logger.error(`[CSPL] after_tool_call error: ${err}`);
|
|
339
|
+
const { deliverSubagentFinalResult } = await import("./src/outbound.js");
|
|
340
|
+
logger.log(`[XY-SUBAGENT-END] Using cached XY config`);
|
|
341
|
+
await deliverSubagentFinalResult({
|
|
342
|
+
config: config,
|
|
343
|
+
state: transition.state,
|
|
344
|
+
reason: "all-subagents-ended-after-parent-settled",
|
|
345
|
+
});
|
|
346
|
+
logger.log(`[XY-SUBAGENT-END] Finalized A2A session after all subagents ended`);
|
|
63
347
|
}
|
|
64
|
-
}
|
|
348
|
+
}
|
|
349
|
+
catch (err) {
|
|
350
|
+
logger.error(`[XY-SUBAGENT-END] Error in subagent_ended hook:`, err);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function registerFullHooks(api) {
|
|
355
|
+
// SUBAGENT HOOKS: track subagent spawn/end lifecycle for session keep-alive
|
|
356
|
+
registerSubagentHooks(api);
|
|
357
|
+
// SKILL RETRIEVER HOOK: before_prompt_build hook
|
|
358
|
+
const pluginConfig = api.pluginConfig || {};
|
|
359
|
+
const skillRetrieverConfig = normalizeToolRetrieverConfig({
|
|
360
|
+
enabled: pluginConfig.skillRetrieverEnabled ?? true,
|
|
361
|
+
maxTools: pluginConfig.skillRetrieverMaxTools ?? 2,
|
|
362
|
+
includeUninstalledOnly: true,
|
|
363
|
+
envFilePath: "~/.openclaw/.xiaoyienv",
|
|
364
|
+
timeoutMs: pluginConfig.skillRetrieverTimeoutMs ?? 1000,
|
|
365
|
+
});
|
|
366
|
+
const beforePromptBuildHandler = createBeforePromptBuildHandler(skillRetrieverConfig);
|
|
367
|
+
api.on("before_prompt_build", async (event, ctx) => {
|
|
368
|
+
logger.log(`[BEFORE_PROMPT_BUILD] hook fired, sessionKey=${ctx.sessionKey || "undefined"}, sessionId=${ctx.sessionId || "undefined"}`);
|
|
369
|
+
return beforePromptBuildHandler(event, ctx);
|
|
370
|
+
});
|
|
371
|
+
registerSelfEvolutionToolResultNudge(api);
|
|
372
|
+
}
|
|
373
|
+
const plugin = definePluginEntry({
|
|
374
|
+
id: "xiaoyi-channel",
|
|
375
|
+
name: "Xiaoyi Channel",
|
|
376
|
+
description: "Xiaoyi channel plugin - Xiaoyi A2A protocol integration",
|
|
377
|
+
register(api) {
|
|
378
|
+
// Always register the provider so wrapStreamFn/prepareExtraParams work
|
|
379
|
+
// in ALL registration modes (not just "full").
|
|
380
|
+
api.registerProvider(xiaoyiProvider);
|
|
381
|
+
// Register the compaction provider so openclaw's safeguard hook uses
|
|
382
|
+
// our summarization path (which injects x-hag-trace-id) instead of the
|
|
383
|
+
// built-in LLM path that bypasses wrapStreamFn.
|
|
384
|
+
api.registerCompactionProvider(xiaoyiCompactionProvider);
|
|
385
|
+
if (api.registrationMode === "cli-metadata") {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (api.registrationMode === "tool-discovery") {
|
|
389
|
+
registerFullHooks(api);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
// Register channel plugin and set runtime
|
|
393
|
+
api.registerChannel({ plugin: xyPlugin });
|
|
394
|
+
setXYRuntime(api.runtime);
|
|
395
|
+
if (api.registrationMode === "discovery") {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (api.registrationMode === "full") {
|
|
399
|
+
registerFullHooks(api);
|
|
400
|
+
// CSPL sentinel hook: before_tool_call + after_tool_call security scanning
|
|
401
|
+
registerSentinelHook(api);
|
|
402
|
+
// CSPL skill scope hook: before_install security scanning
|
|
403
|
+
registerSkillScopeHook(api);
|
|
404
|
+
// Cron detection hook: marks toolCallIds from cron sessions
|
|
405
|
+
registerCronDetectionHook(api);
|
|
406
|
+
// CLI exec hook: intercepts built-in exec for HarmonyOS CLI skill tools
|
|
407
|
+
registerCLIHook(api);
|
|
408
|
+
// Cron recovery hook: prunes stale cron-push-map and pushData on gateway startup
|
|
409
|
+
registerCronRecoveryHook(api);
|
|
410
|
+
// Skills diagnostic hook: log skill usage (detected via SKILL.md reads)
|
|
411
|
+
registerSkillsDiagnosticHook(api);
|
|
412
|
+
}
|
|
65
413
|
},
|
|
66
|
-
};
|
|
414
|
+
});
|
|
67
415
|
export default plugin;
|
|
@@ -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 {};
|