@ynhcj/xiaoyi-channel 0.0.166-beta → 0.0.167-beta

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.
@@ -396,7 +396,12 @@ export function createXYReplyDispatcher(params) {
396
396
  }
397
397
  const currentTaskId = getActiveTaskId();
398
398
  const currentMessageId = getActiveMessageId();
399
- const text = payload.text ?? "";
399
+ let text = payload.text ?? "";
400
+ // Strip "Reasoning:" prefix that some reasoning models add to their thinking output
401
+ const lines = text.split(/\r?\n/);
402
+ if (lines[0]?.trim() === "Reasoning:") {
403
+ text = lines.slice(1).join("\n").trim();
404
+ }
400
405
  try {
401
406
  if (text.length > 0) {
402
407
  // 🔑 将模型真实的thinking/reasoning内容通过reasoningText转发
@@ -0,0 +1,6 @@
1
+ import type { SessionContext } from "./session-manager.js";
2
+ /**
3
+ * XY check plugin privilege tool - checks user authorization for device-side tools
4
+ * used in scheduled tasks.
5
+ */
6
+ export declare function createCheckPluginPrivilegeTool(ctx: SessionContext): any;
@@ -0,0 +1,180 @@
1
+ // Check plugin privilege tool implementation
2
+ import { getXYWebSocketManager } from "../client.js";
3
+ import { sendCommand } from "../formatter.js";
4
+ import { getCurrentTaskId } from "../task-manager.js";
5
+ import { logger } from "../utils/logger.js";
6
+ /**
7
+ * Mapping from intent name to required permission IDs.
8
+ */
9
+ const INTENT_PERMISSION_MAP = {
10
+ GetCurrentLocation: ["ohos.permission.LOCATION", "ohos.permission.APPROXIMATELY_LOCATION"],
11
+ SearchCalendarEvent: ["ohos.permission.READ_WHOLE_CALENDAR"],
12
+ CreateCalendarEvent: ["ohos.permission.WRITE_WHOLE_CALENDAR"],
13
+ DeleteCalendarEvent: ["ohos.permission.WRITE_WHOLE_CALENDAR"],
14
+ ModifyCalendarEvent: ["ohos.permission.WRITE_WHOLE_CALENDAR"],
15
+ SearchNote: ["ohos.permission.READ_NOTE"],
16
+ CreateNote: ["ohos.permission.WRITE_NOTE"],
17
+ ModifyNote: ["ohos.permission.WRITE_NOTE"],
18
+ SearchContactLocal: ["ohos.permission.READ_CONTACTS"],
19
+ SearchPhotoVideo: ["ohos.permission.READ_IMAGEVIDEO"],
20
+ SaveMediaToGallery: ["ohos.permission.WRITE_IMAGEVIDEO"],
21
+ SearchFile: ["ohos.permission.FILE_ACCESS_MANAGER"],
22
+ SaveFileToFileManager: ["ohos.permission.FILE_SAVE_MANAGER"],
23
+ SearchAlarm: ["ohos.permission.READ_ALARM"],
24
+ CreateAlarm: ["ohos.permission.WRITE_ALARM"],
25
+ ModifyAlarm: ["ohos.permission.WRITE_ALARM"],
26
+ DeleteAlarm: ["ohos.permission.WRITE_ALARM"],
27
+ SearchMessage: ["ohos.permission.READ_SMS"],
28
+ SendShortMessage: ["ohos.permission.SEND_MESSAGES"],
29
+ StartCall: ["ohos.permission.PLACE_CALL"],
30
+ };
31
+ /**
32
+ * XY check plugin privilege tool - checks user authorization for device-side tools
33
+ * used in scheduled tasks.
34
+ */
35
+ export function createCheckPluginPrivilegeTool(ctx) {
36
+ const { config, sessionId, taskId, messageId } = ctx;
37
+ return {
38
+ name: "check_plugin_privilege",
39
+ label: "Check Plugin Privilege",
40
+ description: "定时任务权限检查工具。" +
41
+ "【使用场景】仅在创建定时任务时使用,严禁在其他场景调用。当识别到定时任务中需要使用用户设备侧工具时,必须调用此工具进行权限检查。" +
42
+ "【调用前提】调用此工具前,必须确认用户定时任务中提到的工具在当前模型可使用的工具列表中存在。如果当前工具列表中不存在符合用户诉求的工具定义,则不要调用此工具,而是直接告知用户当前设备不支持该功能。" +
43
+ "【支持的意图名称及对应权限】" +
44
+ "GetCurrentLocation(获取用户位置), " +
45
+ "SearchCalendarEvent(搜索用户日程), " +
46
+ "CreateCalendarEvent(新建用户日程), " +
47
+ "DeleteCalendarEvent(删除用户日程), " +
48
+ "ModifyCalendarEvent(修改用户日程), " +
49
+ "SearchNote(搜索用户备忘录), " +
50
+ "CreateNote(新建用户备忘录), " +
51
+ "ModifyNote(修改用户备忘录), " +
52
+ "SearchContactLocal(搜索用户联系人), " +
53
+ "SearchPhotoVideo(搜索用户图库照片或视频), " +
54
+ "SaveMediaToGallery(保存图片/视频到图库), " +
55
+ "SearchFile(搜索用户文件管理里面的文件), " +
56
+ "SaveFileToFileManager(保存文件到文件管理), " +
57
+ "SearchAlarm(搜索闹钟), " +
58
+ "CreateAlarm(新建闹钟), " +
59
+ "ModifyAlarm(修改闹钟), " +
60
+ "DeleteAlarm(删除闹钟), " +
61
+ "SearchMessage(搜索短信), " +
62
+ "SendShortMessage(发送短信), " +
63
+ "StartCall(打电话)。" +
64
+ "【多次调用】如果用户的定时任务指令中涉及多个端侧工具,则依次分别调用此工具检查每个工具的权限。如果调用超时失败,最多重试一次。" +
65
+ "【回复约束】如果工具返回没有授权或其他报错,只需要完整描述没有授权或其他报错内容即可,不需要主动给用户提供解决方案。",
66
+ parameters: {
67
+ type: "object",
68
+ properties: {
69
+ checkIntentName: {
70
+ type: "string",
71
+ description: "需要检查权限的意图名称,必须是支持的意图名称之一,例如:GetCurrentLocation、SearchCalendarEvent、CreateCalendarEvent 等。",
72
+ },
73
+ },
74
+ required: ["checkIntentName"],
75
+ },
76
+ async execute(toolCallId, params) {
77
+ const { checkIntentName } = params;
78
+ // Look up permission IDs for the given intent name
79
+ const permissionId = INTENT_PERMISSION_MAP[checkIntentName];
80
+ if (!permissionId) {
81
+ return {
82
+ content: [
83
+ {
84
+ type: "text",
85
+ text: `不支持的工具意图名称: ${checkIntentName}。请确认该意图名称在支持列表中。`,
86
+ },
87
+ ],
88
+ };
89
+ }
90
+ // Get WebSocket manager
91
+ const wsManager = getXYWebSocketManager(config);
92
+ // Build CheckPlugInPrivilege command
93
+ const command = {
94
+ header: {
95
+ namespace: "Common",
96
+ name: "Action",
97
+ },
98
+ payload: {
99
+ cardParam: {},
100
+ executeParam: {
101
+ achieveType: "INTENT",
102
+ actionResponse: true,
103
+ bundleName: "com.huawei.hmos.vassistant",
104
+ dimension: "",
105
+ executeMode: "background",
106
+ intentName: "CheckPlugInPrivilege",
107
+ intentParam: {
108
+ checkIntentName: "CheckPluginPrivilege",
109
+ permissionId,
110
+ },
111
+ needUnlock: false,
112
+ permissionId: [],
113
+ timeOut: 5,
114
+ },
115
+ needUploadResult: true,
116
+ pageControlRelated: false,
117
+ responses: [
118
+ {
119
+ displayText: "",
120
+ resultCode: "",
121
+ ttsText: "",
122
+ },
123
+ ],
124
+ },
125
+ };
126
+ // Send command and wait for response (60 second timeout)
127
+ return new Promise((resolve, reject) => {
128
+ const timeout = setTimeout(() => {
129
+ wsManager.off("data-event", handler);
130
+ logger.error("超时: 检查插件权限超时(60秒)", { toolCallId, checkIntentName });
131
+ reject(new Error(`检查插件权限超时(60秒), intentName: ${checkIntentName}`));
132
+ }, 60000);
133
+ // Listen for data events from WebSocket
134
+ const handler = (event) => {
135
+ if (event.intentName === "CheckPlugInPrivilege") {
136
+ clearTimeout(timeout);
137
+ wsManager.off("data-event", handler);
138
+ if (event.status === "success" && event.outputs) {
139
+ resolve({
140
+ content: [
141
+ {
142
+ type: "text",
143
+ text: JSON.stringify(event.outputs),
144
+ },
145
+ ],
146
+ });
147
+ }
148
+ else {
149
+ resolve({
150
+ content: [
151
+ {
152
+ type: "text",
153
+ text: JSON.stringify(event.outputs),
154
+ },
155
+ ],
156
+ });
157
+ }
158
+ }
159
+ };
160
+ // Register event handler
161
+ wsManager.on("data-event", handler);
162
+ // Send the command
163
+ const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
164
+ sendCommand({
165
+ config,
166
+ sessionId,
167
+ taskId: currentTaskId,
168
+ messageId,
169
+ command,
170
+ toolCallId,
171
+ }).then(() => {
172
+ }).catch((error) => {
173
+ clearTimeout(timeout);
174
+ wsManager.off("data-event", handler);
175
+ reject(error);
176
+ });
177
+ });
178
+ },
179
+ };
180
+ }
@@ -19,6 +19,7 @@ import { createAgentAsSkillTool } from "./agent-as-skill-tool.js";
19
19
  import { createDiscoverCrossDevicesTool } from "./discover-cross-devices-tool.js";
20
20
  import { createSendCrossDeviceTaskTool } from "./send-cross-device-task-tool.js";
21
21
  import { createDisplayA2UICardTool } from "./display-a2ui-card-tool.js";
22
+ import { createCheckPluginPrivilegeTool } from "./check-plugin-privilege-tool.js";
22
23
  import { logger } from "../utils/logger.js";
23
24
  /**
24
25
  * Create all XY channel tools for the given session context.
@@ -54,5 +55,6 @@ export function createAllTools(ctx) {
54
55
  createSaveSelfEvolutionSkillTool(ctx),
55
56
  createLoginTokenTool(ctx),
56
57
  createAgentAsSkillTool(ctx),
58
+ createCheckPluginPrivilegeTool(ctx),
57
59
  ];
58
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.166-beta",
3
+ "version": "0.0.167-beta",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",