@ynhcj/xiaoyi-channel 0.0.173-next → 0.0.174-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.
@@ -25,14 +25,12 @@ import { loginTokenTool } from "./tools/login-token-tool.js";
25
25
  import { agentAsSkillTool } from "./tools/agent-as-skill-tool.js";
26
26
  import { discoverCrossDevicesTool } from "./tools/discover-cross-devices-tool.js";
27
27
  import { sendCrossDeviceTaskTool } from "./tools/send-cross-device-task-tool.js";
28
- import { displayA2UICardTool } from "./tools/display-a2ui-card-tool.js";
29
28
  import { displayA2UICardByPathTool } from "./tools/display-a2ui-card-bypath-tool.js";
30
29
  import { checkPluginPrivilegeTool } from "./tools/check-plugin-privilege-tool.js";
31
30
  const ALL_TOOLS = [
32
31
  locationTool,
33
32
  discoverCrossDevicesTool,
34
33
  sendCrossDeviceTaskTool,
35
- displayA2UICardTool,
36
34
  displayA2UICardByPathTool,
37
35
  callDeviceTool,
38
36
  getNoteToolSchemaTool,
@@ -19,7 +19,6 @@ import { createLoginTokenTool } from "./login-token-tool.js";
19
19
  import { createAgentAsSkillTool } from "./agent-as-skill-tool.js";
20
20
  import { createDiscoverCrossDevicesTool } from "./discover-cross-devices-tool.js";
21
21
  import { createSendCrossDeviceTaskTool } from "./send-cross-device-task-tool.js";
22
- import { createDisplayA2UICardTool } from "./display-a2ui-card-tool.js";
23
22
  import { createDisplayA2UICardByPathTool } from "./display-a2ui-card-bypath-tool.js";
24
23
  import { createCheckPluginPrivilegeTool } from "./check-plugin-privilege-tool.js";
25
24
  import { logger } from "../utils/logger.js";
@@ -39,7 +38,6 @@ export function createAllTools(ctx) {
39
38
  createLocationTool(ctx),
40
39
  createDiscoverCrossDevicesTool(ctx),
41
40
  createSendCrossDeviceTaskTool(ctx),
42
- createDisplayA2UICardTool(ctx),
43
41
  createDisplayA2UICardByPathTool(ctx),
44
42
  createCallDeviceTool(ctx),
45
43
  createGetNoteToolSchemaTool(ctx),
@@ -32,7 +32,6 @@ const DEVICE_TOOL_POLICY = {
32
32
  "image_reading",
33
33
  "convert_time_to_utc8_time",
34
34
  "save_self_evolution_skill",
35
- "displayA2UICard",
36
35
  "display-a2ui-card-bypath",
37
36
  ],
38
37
  },
@@ -1,27 +1,2 @@
1
- export declare const displayA2UICardTool: {
2
- name: string;
3
- label: string;
4
- description: string;
5
- parameters: {
6
- type: string;
7
- properties: {
8
- cardId: {
9
- type: string;
10
- description: string;
11
- };
12
- cardData: {
13
- oneOf: {
14
- type: string;
15
- }[];
16
- description: string;
17
- };
18
- };
19
- required: string[];
20
- };
21
- execute(toolCallId: string, params: any): Promise<{
22
- content: {
23
- type: string;
24
- text: string;
25
- }[];
26
- }>;
27
- };
1
+ import type { SessionContext } from "./session-manager.js";
2
+ export declare function createDisplayA2UICardTool(ctx: SessionContext): any;
@@ -1,6 +1,6 @@
1
1
  import { sendCommand } from "../formatter.js";
2
+ import { getCurrentMessageId, getCurrentTaskId } from "../task-manager.js";
2
3
  import { logger } from "../utils/logger.js";
3
- import { getCurrentSessionContext } from './session-manager.js';
4
4
  class ToolInputError extends Error {
5
5
  status = 400;
6
6
  constructor(message) {
@@ -11,72 +11,75 @@ class ToolInputError extends Error {
11
11
  function isJsonObjectOrArray(value) {
12
12
  return !!value && typeof value === "object";
13
13
  }
14
- export const displayA2UICardTool = {
15
- name: "displayA2UICard",
16
- label: "Display A2UI Card",
17
- description: "当模型根据 MCP 工具返回结果判断需要向端侧下发 A2UI card 时调用。参数 cardId 和 cardData 由模型根据 MCP 工具返回结果传入,本工具只负责下发卡片展示指令。",
18
- parameters: {
19
- type: "object",
20
- properties: {
21
- cardId: {
22
- type: "string",
23
- description: "A2UI card 的唯一标识。",
24
- },
25
- cardData: {
26
- oneOf: [
27
- { type: "object" },
28
- { type: "array" },
29
- ],
30
- description: "A2UI card 渲染所需的 JSON 对象或 JSON 数组,由模型根据 MCP 工具返回结果填充。",
14
+ export function createDisplayA2UICardTool(ctx) {
15
+ const { config, sessionId, taskId, messageId } = ctx;
16
+ return {
17
+ name: "displayA2UICard",
18
+ label: "Display A2UI Card",
19
+ description: "当模型根据 MCP 工具返回结果判断需要向端侧下发 A2UI card 时调用。参数 cardId 和 cardData 由模型根据 MCP 工具返回结果传入,本工具只负责下发卡片展示指令。",
20
+ parameters: {
21
+ type: "object",
22
+ properties: {
23
+ cardId: {
24
+ type: "string",
25
+ description: "A2UI card 的唯一标识。",
26
+ },
27
+ cardData: {
28
+ oneOf: [
29
+ { type: "object" },
30
+ { type: "array" },
31
+ ],
32
+ description: "A2UI card 渲染所需的 JSON 对象或 JSON 数组,由模型根据 MCP 工具返回结果填充。",
33
+ },
31
34
  },
35
+ required: ["cardId", "cardData"],
32
36
  },
33
- required: ["cardId", "cardData"],
34
- },
35
- async execute(toolCallId, params) {
36
- const _c = getCurrentSessionContext();
37
- const { config, sessionId, taskId, messageId } = _c;
38
- const cardId = typeof params?.cardId === "string" ? params.cardId.trim() : "";
39
- const cardData = params?.cardData;
40
- if (!cardId) {
41
- throw new ToolInputError("缺少必填参数: cardId");
42
- }
43
- if (!isJsonObjectOrArray(cardData)) {
44
- throw new ToolInputError("缺少必填参数: cardData,且必须是 JSON 对象或 JSON 数组");
45
- }
46
- const command = {
47
- header: {
48
- namespace: "Common",
49
- name: "DisplayFACard",
50
- },
51
- payload: {
52
- isA2ui: true,
53
- a2uiParam: {
54
- cardId,
55
- cardData,
37
+ async execute(toolCallId, params) {
38
+ const cardId = typeof params?.cardId === "string" ? params.cardId.trim() : "";
39
+ const cardData = params?.cardData;
40
+ if (!cardId) {
41
+ throw new ToolInputError("缺少必填参数: cardId");
42
+ }
43
+ if (!isJsonObjectOrArray(cardData)) {
44
+ throw new ToolInputError("缺少必填参数: cardData,且必须是 JSON 对象或 JSON 数组");
45
+ }
46
+ const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
47
+ const currentMessageId = getCurrentMessageId(sessionId) ?? messageId;
48
+ const command = {
49
+ header: {
50
+ namespace: "Common",
51
+ name: "DisplayFACard",
56
52
  },
57
- },
58
- };
59
- logger.log(`[DISPLAY-A2UI-CARD] sending card, cardId=${cardId}`);
60
- await sendCommand({
61
- config,
62
- sessionId,
63
- taskId,
64
- messageId,
65
- command,
66
- toolCallId,
67
- });
68
- logger.log(`[DISPLAY-A2UI-CARD] card sent successfully, cardId=${cardId}`);
69
- return {
70
- content: [
71
- {
72
- type: "text",
73
- text: JSON.stringify({
74
- success: true,
53
+ payload: {
54
+ isA2ui: true,
55
+ a2uiParam: {
75
56
  cardId,
76
- message: "A2UI card display command sent successfully.",
77
- }),
57
+ cardData,
58
+ },
78
59
  },
79
- ],
80
- };
81
- },
82
- };
60
+ };
61
+ logger.log(`[DISPLAY-A2UI-CARD] sending card, cardId=${cardId}`);
62
+ await sendCommand({
63
+ config,
64
+ sessionId,
65
+ taskId: currentTaskId,
66
+ messageId: currentMessageId,
67
+ command,
68
+ toolCallId,
69
+ });
70
+ logger.log(`[DISPLAY-A2UI-CARD] card sent successfully, cardId=${cardId}`);
71
+ return {
72
+ content: [
73
+ {
74
+ type: "text",
75
+ text: JSON.stringify({
76
+ success: true,
77
+ cardId,
78
+ message: "A2UI card display command sent successfully.",
79
+ }),
80
+ },
81
+ ],
82
+ };
83
+ },
84
+ };
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.173-next",
3
+ "version": "0.0.174-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",