@ynhcj/xiaoyi-channel 0.0.97-next → 0.0.98-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 CHANGED
@@ -1,11 +1,8 @@
1
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
1
  declare const _default: {
3
2
  id: string;
4
3
  name: string;
5
4
  description: string;
6
- configSchema: import("openclaw/plugin-sdk").ChannelConfigSchema;
7
- register: (api: OpenClawPluginApi) => void;
8
- channelPlugin: import("openclaw/plugin-sdk").ChannelPlugin;
9
- setChannelRuntime?: (runtime: import("openclaw/plugin-sdk").PluginRuntime) => void;
10
- };
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">;
11
8
  export default _default;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineChannelPluginEntry } from "openclaw/plugin-sdk/core";
1
+ import { definePluginEntry } from "openclaw/plugin-sdk/core";
2
2
  import { xiaoyiProvider } from "./src/provider.js";
3
3
  import { xyPlugin } from "./src/channel.js";
4
4
  import { callCsplApi } from "./src/cspl/call-api.js";
@@ -9,61 +9,79 @@ import { tryInjectSteer } from "./src/steer-injector.js";
9
9
  import { registerSelfEvolutionToolResultNudge } from "./src/self-evolution-tool-result-nudge.js";
10
10
  import { createBeforePromptBuildHandler } from "./src/skill-retriever/hooks.js";
11
11
  import { normalizeToolRetrieverConfig } from "./src/skill-retriever/config.js";
12
- export default defineChannelPluginEntry({
13
- id: "xiaoyi-channel",
14
- name: "Xiaoyi Channel",
15
- description: "Xiaoyi channel plugin - Xiaoyi A2A protocol integration",
16
- plugin: xyPlugin,
17
- setRuntime: setXYRuntime,
18
- registerFull(api) {
19
- api.registerProvider(xiaoyiProvider);
20
- // SKILL RETRIEVER HOOK: before_prompt_build hook
21
- const pluginConfig = api.pluginConfig || {};
22
- const skillRetrieverConfig = normalizeToolRetrieverConfig({
23
- enabled: pluginConfig.skillRetrieverEnabled ?? true,
24
- maxTools: pluginConfig.skillRetrieverMaxTools ?? 2,
25
- includeUninstalledOnly: true,
26
- envFilePath: "~/.openclaw/.xiaoyienv",
27
- timeoutMs: pluginConfig.skillRetrieverTimeoutMs ?? 1000,
28
- });
29
- const beforePromptBuildHandler = createBeforePromptBuildHandler(skillRetrieverConfig);
30
- api.on("before_prompt_build", beforePromptBuildHandler);
31
- registerSelfEvolutionToolResultNudge(api);
32
- api.on("after_tool_call", async (event, ctx) => {
33
- if (!ALLOWED_TOOLS.includes(event.toolName)) {
12
+ function registerFullHooks(api) {
13
+ // SKILL RETRIEVER HOOK: before_prompt_build hook
14
+ const pluginConfig = api.pluginConfig || {};
15
+ const skillRetrieverConfig = normalizeToolRetrieverConfig({
16
+ enabled: pluginConfig.skillRetrieverEnabled ?? true,
17
+ maxTools: pluginConfig.skillRetrieverMaxTools ?? 2,
18
+ includeUninstalledOnly: true,
19
+ envFilePath: "~/.openclaw/.xiaoyienv",
20
+ timeoutMs: pluginConfig.skillRetrieverTimeoutMs ?? 1000,
21
+ });
22
+ const beforePromptBuildHandler = createBeforePromptBuildHandler(skillRetrieverConfig);
23
+ api.on("before_prompt_build", beforePromptBuildHandler);
24
+ registerSelfEvolutionToolResultNudge(api);
25
+ api.on("after_tool_call", async (event, ctx) => {
26
+ if (!ALLOWED_TOOLS.includes(event.toolName)) {
27
+ return;
28
+ }
29
+ console.log(`[SENTINEL HOOK] after_tool_call triggered: toolName=${event.toolName}, sessionKey=${ctx.sessionKey ?? "none"}`);
30
+ try {
31
+ const resultText = extractResultText(event, event.toolName);
32
+ const resultLength = resultText.length;
33
+ if (resultLength <= MIN_TEXT_LENGTH || resultLength > MAX_TOTAL_LENGTH) {
34
34
  return;
35
35
  }
36
- console.log(`[SENTINEL HOOK] after_tool_call triggered: toolName=${event.toolName}, sessionKey=${ctx.sessionKey ?? "none"}`);
37
- try {
38
- const resultText = extractResultText(event, event.toolName);
39
- const resultLength = resultText.length;
40
- if (resultLength <= MIN_TEXT_LENGTH || resultLength > MAX_TOTAL_LENGTH) {
41
- return;
42
- }
43
- const questionText = {
44
- subSceneID: "TOOL_OUTPUT",
45
- tool: event.toolName,
46
- output: [{ content: "" }],
47
- };
48
- const originText = processText(resultText);
49
- questionText.output[0].content = originText;
50
- let finalJson = JSON.stringify(questionText);
51
- if (finalJson.length > MAX_TEXT_LENGTH) {
52
- const diff = finalJson.length - MAX_TEXT_LENGTH;
53
- const { text: trimmed } = validateAndTruncateText(originText, MAX_TEXT_LENGTH - diff);
54
- questionText.output[0].content = trimmed;
55
- finalJson = JSON.stringify(questionText);
56
- }
57
- const response = await callCsplApi(finalJson, api.config);
58
- const result = parseSecurityResult(response);
59
- console.log(`[SENTINEL HOOK] Security result: status=${result.status}`);
60
- if (result.status === "REJECT") {
61
- await tryInjectSteer(ctx.sessionKey, STEER_ABORT_MESSAGE);
62
- }
36
+ const questionText = {
37
+ subSceneID: "TOOL_OUTPUT",
38
+ tool: event.toolName,
39
+ output: [{ content: "" }],
40
+ };
41
+ const originText = processText(resultText);
42
+ questionText.output[0].content = originText;
43
+ let finalJson = JSON.stringify(questionText);
44
+ if (finalJson.length > MAX_TEXT_LENGTH) {
45
+ const diff = finalJson.length - MAX_TEXT_LENGTH;
46
+ const { text: trimmed } = validateAndTruncateText(originText, MAX_TEXT_LENGTH - diff);
47
+ questionText.output[0].content = trimmed;
48
+ finalJson = JSON.stringify(questionText);
63
49
  }
64
- catch (err) {
65
- api.logger.error(`[SENTINEL HOOK] after_tool_call error: ${err}`);
50
+ const response = await callCsplApi(finalJson, api.config);
51
+ const result = parseSecurityResult(response);
52
+ console.log(`[SENTINEL HOOK] Security result: status=${result.status}`);
53
+ if (result.status === "REJECT") {
54
+ await tryInjectSteer(ctx.sessionKey, STEER_ABORT_MESSAGE);
66
55
  }
67
- });
56
+ }
57
+ catch (err) {
58
+ api.logger.error(`[SENTINEL HOOK] after_tool_call error: ${err}`);
59
+ }
60
+ });
61
+ }
62
+ export default definePluginEntry({
63
+ id: "xiaoyi-channel",
64
+ name: "Xiaoyi Channel",
65
+ description: "Xiaoyi channel plugin - Xiaoyi A2A protocol integration",
66
+ register(api) {
67
+ // Always register the provider so wrapStreamFn/prepareExtraParams work
68
+ // in ALL registration modes (not just "full").
69
+ api.registerProvider(xiaoyiProvider);
70
+ if (api.registrationMode === "cli-metadata") {
71
+ return;
72
+ }
73
+ if (api.registrationMode === "tool-discovery") {
74
+ registerFullHooks(api);
75
+ return;
76
+ }
77
+ // Register channel plugin and set runtime
78
+ api.registerChannel({ plugin: xyPlugin });
79
+ setXYRuntime(api.runtime);
80
+ if (api.registrationMode === "discovery") {
81
+ return;
82
+ }
83
+ if (api.registrationMode === "full") {
84
+ registerFullHooks(api);
85
+ }
68
86
  },
69
87
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.97-next",
3
+ "version": "0.0.98-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",