@ynhcj/xiaoyi-channel 0.0.185-beta → 0.0.185-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.
Files changed (150) hide show
  1. package/dist/index.js +141 -1
  2. package/dist/src/acp-session-binding.d.ts +37 -0
  3. package/dist/src/acp-session-binding.js +237 -0
  4. package/dist/src/bot.js +62 -33
  5. package/dist/src/channel.js +68 -64
  6. package/dist/src/client.d.ts +5 -0
  7. package/dist/src/client.js +10 -0
  8. package/dist/src/cron-command.d.ts +2 -0
  9. package/dist/src/cron-command.js +14 -8
  10. package/dist/src/cron-query-handler.js +36 -0
  11. package/dist/src/cspl/call_api.js +4 -2
  12. package/dist/src/cspl/sentinel_hook.js +9 -8
  13. package/dist/src/cspl/upload_file.js +2 -2
  14. package/dist/src/formatter.js +72 -36
  15. package/dist/src/log-reporter/config-loader.d.ts +11 -0
  16. package/dist/src/log-reporter/config-loader.js +68 -0
  17. package/dist/src/log-reporter/cursor-store.d.ts +5 -0
  18. package/dist/src/log-reporter/cursor-store.js +26 -0
  19. package/dist/src/log-reporter/index.d.ts +10 -0
  20. package/dist/src/log-reporter/index.js +77 -0
  21. package/dist/src/log-reporter/reporter.d.ts +6 -0
  22. package/dist/src/log-reporter/reporter.js +17 -0
  23. package/dist/src/log-reporter/scanner.d.ts +6 -0
  24. package/dist/src/log-reporter/scanner.js +82 -0
  25. package/dist/src/log-reporter/types.d.ts +59 -0
  26. package/dist/src/log-reporter/types.js +2 -0
  27. package/dist/src/log-reporter/uploader.d.ts +6 -0
  28. package/dist/src/log-reporter/uploader.js +32 -0
  29. package/dist/src/memory-query-handler.d.ts +1 -0
  30. package/dist/src/memory-query-handler.js +283 -0
  31. package/dist/src/monitor.js +29 -9
  32. package/dist/src/outbound.js +5 -0
  33. package/dist/src/parser.d.ts +12 -0
  34. package/dist/src/parser.js +39 -13
  35. package/dist/src/provider.js +79 -16
  36. package/dist/src/reply-dispatcher.d.ts +3 -0
  37. package/dist/src/reply-dispatcher.js +166 -164
  38. package/dist/src/self-evolution-handler.js +2 -1
  39. package/dist/src/task-manager.d.ts +5 -6
  40. package/dist/src/task-manager.js +5 -9
  41. package/dist/src/tools/agent-as-skill-tool.d.ts +41 -2
  42. package/dist/src/tools/agent-as-skill-tool.js +144 -151
  43. package/dist/src/tools/calendar-tool.d.ts +24 -2
  44. package/dist/src/tools/calendar-tool.js +115 -117
  45. package/dist/src/tools/call-device-tool.d.ts +20 -6
  46. package/dist/src/tools/call-device-tool.js +116 -138
  47. package/dist/src/tools/call-phone-tool.d.ts +21 -2
  48. package/dist/src/tools/call-phone-tool.js +112 -114
  49. package/dist/src/tools/check-plugin-privilege-tool.d.ts +16 -2
  50. package/dist/src/tools/check-plugin-privilege-tool.js +141 -143
  51. package/dist/src/tools/create-alarm-tool.d.ts +39 -2
  52. package/dist/src/tools/create-alarm-tool.js +229 -231
  53. package/dist/src/tools/create-all-tools.js +8 -4
  54. package/dist/src/tools/delete-alarm-tool.d.ts +15 -2
  55. package/dist/src/tools/delete-alarm-tool.js +134 -136
  56. package/dist/src/tools/device-tool-map.d.ts +1 -1
  57. package/dist/src/tools/device-tool-map.js +9 -2
  58. package/dist/src/tools/discover-cross-devices-tool.d.ts +16 -2
  59. package/dist/src/tools/discover-cross-devices-tool.js +121 -124
  60. package/dist/src/tools/display-a2ui-card-bypath-tool.d.ts +21 -0
  61. package/dist/src/tools/display-a2ui-card-bypath-tool.js +65 -0
  62. package/dist/src/tools/get-alarm-tool-schema.d.ts +1 -2
  63. package/dist/src/tools/get-alarm-tool-schema.js +10 -16
  64. package/dist/src/tools/get-calendar-tool-schema.d.ts +1 -2
  65. package/dist/src/tools/get-calendar-tool-schema.js +8 -12
  66. package/dist/src/tools/get-collection-tool-schema.d.ts +1 -2
  67. package/dist/src/tools/get-collection-tool-schema.js +9 -11
  68. package/dist/src/tools/get-contact-tool-schema.d.ts +1 -2
  69. package/dist/src/tools/get-contact-tool-schema.js +10 -16
  70. package/dist/src/tools/get-device-file-tool-schema.d.ts +1 -2
  71. package/dist/src/tools/get-device-file-tool-schema.js +9 -13
  72. package/dist/src/tools/get-email-tool-schema.d.ts +1 -2
  73. package/dist/src/tools/get-email-tool-schema.js +8 -11
  74. package/dist/src/tools/get-note-tool-schema.d.ts +1 -2
  75. package/dist/src/tools/get-note-tool-schema.js +9 -14
  76. package/dist/src/tools/get-photo-tool-schema.d.ts +1 -2
  77. package/dist/src/tools/get-photo-tool-schema.js +9 -12
  78. package/dist/src/tools/image-reading-tool.d.ts +28 -2
  79. package/dist/src/tools/image-reading-tool.js +76 -76
  80. package/dist/src/tools/location-tool.d.ts +11 -2
  81. package/dist/src/tools/location-tool.js +93 -92
  82. package/dist/src/tools/login-token-tool.d.ts +20 -2
  83. package/dist/src/tools/login-token-tool.js +123 -125
  84. package/dist/src/tools/modify-alarm-tool.d.ts +47 -2
  85. package/dist/src/tools/modify-alarm-tool.js +250 -252
  86. package/dist/src/tools/modify-note-tool.d.ts +20 -2
  87. package/dist/src/tools/modify-note-tool.js +107 -109
  88. package/dist/src/tools/note-tool.d.ts +20 -2
  89. package/dist/src/tools/note-tool.js +106 -108
  90. package/dist/src/tools/query-app-message-tool.d.ts +28 -2
  91. package/dist/src/tools/query-app-message-tool.js +111 -113
  92. package/dist/src/tools/query-memory-data-tool.d.ts +28 -2
  93. package/dist/src/tools/query-memory-data-tool.js +112 -114
  94. package/dist/src/tools/query-todo-task-tool.d.ts +24 -2
  95. package/dist/src/tools/query-todo-task-tool.js +106 -108
  96. package/dist/src/tools/save-file-to-phone-tool.d.ts +24 -2
  97. package/dist/src/tools/save-file-to-phone-tool.js +130 -132
  98. package/dist/src/tools/save-media-to-gallery-tool.d.ts +24 -2
  99. package/dist/src/tools/save-media-to-gallery-tool.js +137 -139
  100. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +54 -2
  101. package/dist/src/tools/save-self-evolution-skill-tool.js +194 -194
  102. package/dist/src/tools/search-alarm-tool.d.ts +34 -2
  103. package/dist/src/tools/search-alarm-tool.js +174 -176
  104. package/dist/src/tools/search-calendar-tool.d.ts +24 -2
  105. package/dist/src/tools/search-calendar-tool.js +148 -150
  106. package/dist/src/tools/search-contact-tool.d.ts +16 -2
  107. package/dist/src/tools/search-contact-tool.js +101 -103
  108. package/dist/src/tools/search-email-tool.d.ts +21 -2
  109. package/dist/src/tools/search-email-tool.js +110 -112
  110. package/dist/src/tools/search-file-tool.d.ts +16 -2
  111. package/dist/src/tools/search-file-tool.js +104 -106
  112. package/dist/src/tools/search-message-tool.d.ts +16 -2
  113. package/dist/src/tools/search-message-tool.js +103 -105
  114. package/dist/src/tools/search-note-tool.d.ts +16 -2
  115. package/dist/src/tools/search-note-tool.js +98 -100
  116. package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -2
  117. package/dist/src/tools/search-photo-gallery-tool.js +35 -37
  118. package/dist/src/tools/send-cross-device-task-tool.d.ts +35 -2
  119. package/dist/src/tools/send-cross-device-task-tool.js +216 -150
  120. package/dist/src/tools/send-email-tool.d.ts +24 -2
  121. package/dist/src/tools/send-email-tool.js +108 -110
  122. package/dist/src/tools/send-file-to-user-tool.d.ts +20 -2
  123. package/dist/src/tools/send-file-to-user-tool.js +174 -178
  124. package/dist/src/tools/send-html-card-tool.d.ts +20 -2
  125. package/dist/src/tools/send-html-card-tool.js +85 -87
  126. package/dist/src/tools/send-message-tool.d.ts +20 -2
  127. package/dist/src/tools/send-message-tool.js +122 -124
  128. package/dist/src/tools/session-manager.d.ts +19 -52
  129. package/dist/src/tools/session-manager.js +95 -247
  130. package/dist/src/tools/upload-file-tool.d.ts +20 -2
  131. package/dist/src/tools/upload-file-tool.js +80 -82
  132. package/dist/src/tools/upload-photo-tool.d.ts +20 -2
  133. package/dist/src/tools/upload-photo-tool.js +68 -70
  134. package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +32 -2
  135. package/dist/src/tools/xiaoyi-add-collection-tool.js +146 -148
  136. package/dist/src/tools/xiaoyi-collection-tool.d.ts +20 -2
  137. package/dist/src/tools/xiaoyi-collection-tool.js +114 -116
  138. package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +15 -2
  139. package/dist/src/tools/xiaoyi-delete-collection-tool.js +127 -129
  140. package/dist/src/tools/xiaoyi-gui-tool.d.ts +16 -2
  141. package/dist/src/tools/xiaoyi-gui-tool.js +92 -95
  142. package/dist/src/types.d.ts +6 -6
  143. package/dist/src/utils/config-manager.d.ts +3 -2
  144. package/dist/src/utils/config-manager.js +22 -2
  145. package/dist/src/utils/cron-push-map.d.ts +26 -0
  146. package/dist/src/utils/cron-push-map.js +131 -0
  147. package/dist/src/utils/logger.js +3 -14
  148. package/dist/src/websocket.d.ts +1 -1
  149. package/dist/src/websocket.js +29 -13
  150. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
- import { getXYWebSocketManager } from "../client.js";
1
+ import { getCachedXYWebSocketManager } from "../client.js";
2
2
  import { sendCommand } from "../formatter.js";
3
- import { getCurrentTaskId } from "../task-manager.js";
3
+ import { getCurrentSessionContext } from './session-manager.js';
4
4
  import { logger } from "../utils/logger.js";
5
5
  /**
6
6
  * Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
@@ -18,12 +18,10 @@ class ToolInputError extends Error {
18
18
  * XY collection tool - retrieves user's collection data from XiaoYi.
19
19
  * Returns personalized knowledge data saved in user's collection.
20
20
  */
21
- export function createXiaoyiCollectionTool(ctx) {
22
- const { config, sessionId, taskId, messageId } = ctx;
23
- return {
24
- name: "query_collection",
25
- label: "XiaoYi Collection",
26
- description: `检索用户在小艺收藏(也叫小艺帮记)中记下来的公共知识数据,本技能支持查询用户收藏的公共知识数据,也可以根据特定语义化描述进行特定内容的检索,通过参数进行控制。本技能返回结果中,linkTitle是收藏内容的标题,description是对收藏内容的总结,label是收藏内容的标签,linkUrl是可以直接访问的原始内容链接。如果你认为某条数据对用户交互有用,可以通过linkUrl抓取更加丰富的原始数据。
21
+ export const xiaoyiCollectionTool = {
22
+ name: "query_collection",
23
+ label: "XiaoYi Collection",
24
+ description: `检索用户在小艺收藏(也叫小艺帮记)中记下来的公共知识数据,本技能支持查询用户收藏的公共知识数据,也可以根据特定语义化描述进行特定内容的检索,通过参数进行控制。本技能返回结果中,linkTitle是收藏内容的标题,description是对收藏内容的总结,label是收藏内容的标签,linkUrl是可以直接访问的原始内容链接。如果你认为某条数据对用户交互有用,可以通过linkUrl抓取更加丰富的原始数据。
27
25
  注意:
28
26
  a. 操作超时时间为60秒,请勿重复调用此工具
29
27
  b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
@@ -32,118 +30,118 @@ export function createXiaoyiCollectionTool(ctx) {
32
30
 
33
31
  回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
34
32
  `,
35
- parameters: {
36
- type: "object",
37
- properties: {
38
- queryAll: {
39
- type: "string",
40
- description: "非必填参数,描述是否需要查询用户所有收藏数据。如果填入true则表示获取用户所有公共知识数据,其他参数无效。",
41
- },
42
- query: {
43
- type: "string",
44
- description: "非必填参数,queryAll不填或者为false则必填。用户的查询条件,可按照用户query进行检索。",
45
- },
33
+ parameters: {
34
+ type: "object",
35
+ properties: {
36
+ queryAll: {
37
+ type: "string",
38
+ description: "非必填参数,描述是否需要查询用户所有收藏数据。如果填入true则表示获取用户所有公共知识数据,其他参数无效。",
39
+ },
40
+ query: {
41
+ type: "string",
42
+ description: "非必填参数,queryAll不填或者为false则必填。用户的查询条件,可按照用户query进行检索。",
46
43
  },
47
- required: [],
48
44
  },
49
- async execute(toolCallId, params) {
50
- // Validate parameters
51
- const queryAll = params.queryAll;
52
- const query = params.query;
53
- if (queryAll !== "true" && (!query || typeof query !== "string")) {
54
- throw new ToolInputError("queryAll不为true时,query参数必填");
55
- }
56
- // Get WebSocket manager
57
- const wsManager = getXYWebSocketManager(config);
58
- // Build intentParam
59
- const intentParam = {};
60
- if (queryAll === "true") {
61
- intentParam.queryAll = "true";
62
- }
63
- else {
64
- intentParam.queryAll = "false";
65
- intentParam.query = query;
66
- }
67
- // Build QueryCollection command
68
- const command = {
69
- header: {
70
- namespace: "Common",
71
- name: "Action",
45
+ required: [],
46
+ },
47
+ async execute(toolCallId, params) {
48
+ const _c = getCurrentSessionContext();
49
+ const { config, sessionId, taskId, messageId } = _c;
50
+ // Validate parameters
51
+ const queryAll = params.queryAll;
52
+ const query = params.query;
53
+ if (queryAll !== "true" && (!query || typeof query !== "string")) {
54
+ throw new ToolInputError("queryAll不为true时,query参数必填");
55
+ }
56
+ // Get WebSocket manager
57
+ const wsManager = getCachedXYWebSocketManager();
58
+ // Build intentParam
59
+ const intentParam = {};
60
+ if (queryAll === "true") {
61
+ intentParam.queryAll = "true";
62
+ }
63
+ else {
64
+ intentParam.queryAll = "false";
65
+ intentParam.query = query;
66
+ }
67
+ // Build QueryCollection command
68
+ const command = {
69
+ header: {
70
+ namespace: "Common",
71
+ name: "Action",
72
+ },
73
+ payload: {
74
+ cardParam: {},
75
+ executeParam: {
76
+ executeMode: "background",
77
+ intentName: "QueryCollection",
78
+ bundleName: "com.huawei.hmos.vassistant",
79
+ needUnlock: true,
80
+ actionResponse: true,
81
+ appType: "OHOS_APP",
82
+ timeOut: 5,
83
+ intentParam,
84
+ permissionId: [],
85
+ achieveType: "INTENT",
72
86
  },
73
- payload: {
74
- cardParam: {},
75
- executeParam: {
76
- executeMode: "background",
77
- intentName: "QueryCollection",
78
- bundleName: "com.huawei.hmos.vassistant",
79
- needUnlock: true,
80
- actionResponse: true,
81
- appType: "OHOS_APP",
82
- timeOut: 5,
83
- intentParam,
84
- permissionId: [],
85
- achieveType: "INTENT",
87
+ responses: [
88
+ {
89
+ resultCode: "",
90
+ displayText: "",
91
+ ttsText: "",
86
92
  },
87
- responses: [
88
- {
89
- resultCode: "",
90
- displayText: "",
91
- ttsText: "",
92
- },
93
- ],
94
- needUploadResult: true,
95
- noHalfPage: false,
96
- pageControlRelated: false,
97
- },
98
- };
99
- // Send command and wait for response (60 second timeout)
100
- return new Promise((resolve, reject) => {
101
- const timeout = setTimeout(() => {
102
- wsManager.off("data-event", handler);
103
- logger.error("超时: 查询小艺收藏超时(60秒)", { toolCallId });
104
- reject(new Error("查询小艺收藏超时(60秒)"));
105
- }, 60000);
106
- // Listen for data events from WebSocket
107
- const handler = (event) => {
108
- if (event.intentName === "QueryCollection") {
109
- clearTimeout(timeout);
110
- wsManager.off("data-event", handler);
111
- if (event.status === "success" && event.outputs) {
112
- // 成功,直接返回完整的 event.outputs JSON 字符串
113
- resolve({
114
- content: [
115
- {
116
- type: "text",
117
- text: JSON.stringify(event.outputs),
118
- }
119
- ]
120
- });
121
- }
122
- else {
123
- reject(new Error(`查询小艺收藏失败: ${JSON.stringify(event.outputs)}`));
124
- }
125
- }
126
- };
127
- // Register event handler
128
- wsManager.on("data-event", handler);
129
- // Send the command
130
- const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
131
- sendCommand({
132
- config,
133
- sessionId,
134
- taskId: currentTaskId,
135
- messageId,
136
- command,
137
- toolCallId,
138
- })
139
- .then(() => {
140
- })
141
- .catch((error) => {
93
+ ],
94
+ needUploadResult: true,
95
+ noHalfPage: false,
96
+ pageControlRelated: false,
97
+ },
98
+ };
99
+ // Send command and wait for response (60 second timeout)
100
+ return new Promise((resolve, reject) => {
101
+ const timeout = setTimeout(() => {
102
+ wsManager.off("data-event", handler);
103
+ logger.error("超时: 查询小艺收藏超时(60秒)", { toolCallId });
104
+ reject(new Error("查询小艺收藏超时(60秒)"));
105
+ }, 60000);
106
+ // Listen for data events from WebSocket
107
+ const handler = (event) => {
108
+ if (event.intentName === "QueryCollection") {
142
109
  clearTimeout(timeout);
143
110
  wsManager.off("data-event", handler);
144
- reject(error);
145
- });
111
+ if (event.status === "success" && event.outputs) {
112
+ // 成功,直接返回完整的 event.outputs JSON 字符串
113
+ resolve({
114
+ content: [
115
+ {
116
+ type: "text",
117
+ text: JSON.stringify(event.outputs),
118
+ }
119
+ ]
120
+ });
121
+ }
122
+ else {
123
+ reject(new Error(`查询小艺收藏失败: ${JSON.stringify(event.outputs)}`));
124
+ }
125
+ }
126
+ };
127
+ // Register event handler
128
+ wsManager.on("data-event", handler);
129
+ // Send the command
130
+ sendCommand({
131
+ config,
132
+ sessionId,
133
+ taskId,
134
+ messageId,
135
+ command,
136
+ toolCallId,
137
+ })
138
+ .then(() => {
139
+ })
140
+ .catch((error) => {
141
+ clearTimeout(timeout);
142
+ wsManager.off("data-event", handler);
143
+ reject(error);
146
144
  });
147
- },
148
- };
149
- }
145
+ });
146
+ },
147
+ };
@@ -1,5 +1,18 @@
1
- import type { SessionContext } from "./session-manager.js";
2
1
  /**
3
2
  * XY delete collection tool - deletes data from user's XiaoYi collection.
4
3
  */
5
- export declare function createXiaoyiDeleteCollectionTool(ctx: SessionContext): any;
4
+ export declare const xiaoyiDeleteCollectionTool: {
5
+ name: string;
6
+ label: string;
7
+ description: string;
8
+ parameters: {
9
+ type: string;
10
+ properties: {
11
+ itemIds: {
12
+ description: string;
13
+ };
14
+ };
15
+ required: string[];
16
+ };
17
+ execute(toolCallId: string, params: any): Promise<unknown>;
18
+ };
@@ -1,6 +1,6 @@
1
- import { getXYWebSocketManager } from "../client.js";
1
+ import { getCachedXYWebSocketManager } from "../client.js";
2
2
  import { sendCommand } from "../formatter.js";
3
- import { getCurrentTaskId } from "../task-manager.js";
3
+ import { getCurrentSessionContext } from './session-manager.js';
4
4
  import { logger } from "../utils/logger.js";
5
5
  /**
6
6
  * Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
@@ -17,12 +17,10 @@ class ToolInputError extends Error {
17
17
  /**
18
18
  * XY delete collection tool - deletes data from user's XiaoYi collection.
19
19
  */
20
- export function createXiaoyiDeleteCollectionTool(ctx) {
21
- const { config, sessionId, taskId, messageId } = ctx;
22
- return {
23
- name: "delete_collection",
24
- label: "Delete XiaoYi Collection",
25
- description: `从小艺收藏(也叫小艺帮记)中删除之前已保存的公共知识数据。任何用户希望删除已保存到个人知识库的数据都可以调用本技能。如果用户想更新之前的收藏数据,需要先query获取itemId然后再delete,最后执行Add,按照这个步骤完成收藏数据更新。
20
+ export const xiaoyiDeleteCollectionTool = {
21
+ name: "delete_collection",
22
+ label: "Delete XiaoYi Collection",
23
+ description: `从小艺收藏(也叫小艺帮记)中删除之前已保存的公共知识数据。任何用户希望删除已保存到个人知识库的数据都可以调用本技能。如果用户想更新之前的收藏数据,需要先query获取itemId然后再delete,最后执行Add,按照这个步骤完成收藏数据更新。
26
24
  注意:
27
25
  a. 操作超时时间为60秒,请勿重复调用此工具
28
26
  b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
@@ -30,135 +28,135 @@ export function createXiaoyiDeleteCollectionTool(ctx) {
30
28
 
31
29
  回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
32
30
  `,
33
- parameters: {
34
- type: "object",
35
- properties: {
36
- itemIds: {
37
- // 不指定 type,允许传入数组或 JSON 字符串
38
- // 具体的类型验证和转换在 execute 函数内部进行
39
- description: "准备删除的数据的itemId合集。itemId可以由用户指定,也可以从之前检索回来的收藏数据项的itemId字段获取。",
40
- },
31
+ parameters: {
32
+ type: "object",
33
+ properties: {
34
+ itemIds: {
35
+ // 不指定 type,允许传入数组或 JSON 字符串
36
+ // 具体的类型验证和转换在 execute 函数内部进行
37
+ description: "准备删除的数据的itemId合集。itemId可以由用户指定,也可以从之前检索回来的收藏数据项的itemId字段获取。",
41
38
  },
42
- required: ["itemIds"],
43
39
  },
44
- async execute(toolCallId, params) {
45
- // ===== 参数规范化:兼容数组和 JSON 字符串 =====
46
- let itemIds = null;
47
- if (!params.itemIds) {
48
- throw new ToolInputError("缺少必填参数: itemIds");
49
- }
50
- // 情况1: 已经是数组
51
- if (Array.isArray(params.itemIds)) {
52
- itemIds = params.itemIds;
53
- }
54
- // 情况2: 是字符串,尝试解析为 JSON 数组
55
- else if (typeof params.itemIds === 'string') {
56
- try {
57
- const parsed = JSON.parse(params.itemIds);
58
- if (Array.isArray(parsed)) {
59
- itemIds = parsed;
60
- }
61
- else {
62
- throw new ToolInputError("itemIds must be an array or a JSON string representing an array");
63
- }
40
+ required: ["itemIds"],
41
+ },
42
+ async execute(toolCallId, params) {
43
+ const _c = getCurrentSessionContext();
44
+ const { config, sessionId, taskId, messageId } = _c;
45
+ // ===== 参数规范化:兼容数组和 JSON 字符串 =====
46
+ let itemIds = null;
47
+ if (!params.itemIds) {
48
+ throw new ToolInputError("缺少必填参数: itemIds");
49
+ }
50
+ // 情况1: 已经是数组
51
+ if (Array.isArray(params.itemIds)) {
52
+ itemIds = params.itemIds;
53
+ }
54
+ // 情况2: 是字符串,尝试解析为 JSON 数组
55
+ else if (typeof params.itemIds === 'string') {
56
+ try {
57
+ const parsed = JSON.parse(params.itemIds);
58
+ if (Array.isArray(parsed)) {
59
+ itemIds = parsed;
64
60
  }
65
- catch (parseError) {
66
- if (parseError instanceof ToolInputError)
67
- throw parseError;
68
- throw new ToolInputError(`itemIds must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
61
+ else {
62
+ throw new ToolInputError("itemIds must be an array or a JSON string representing an array");
69
63
  }
70
64
  }
71
- // 情况3: 其他类型,报错
72
- else {
73
- throw new ToolInputError(`itemIds must be an array or a JSON string, got ${typeof params.itemIds}`);
65
+ catch (parseError) {
66
+ if (parseError instanceof ToolInputError)
67
+ throw parseError;
68
+ throw new ToolInputError(`itemIds must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
74
69
  }
75
- // 验证数组非空
76
- if (!itemIds || itemIds.length === 0) {
77
- throw new ToolInputError("itemIds array cannot be empty");
78
- }
79
- // Get WebSocket manager
80
- const wsManager = getXYWebSocketManager(config);
81
- // Build DeleteCollection command
82
- const command = {
83
- header: {
84
- namespace: "Common",
85
- name: "Action",
86
- },
87
- payload: {
88
- cardParam: {},
89
- executeParam: {
90
- executeMode: "background",
91
- intentName: "DeleteCollection",
92
- bundleName: "com.huawei.hmos.vassistant",
93
- needUnlock: true,
94
- actionResponse: true,
95
- appType: "OHOS_APP",
96
- timeOut: 5,
97
- intentParam: {
98
- itemIds,
99
- },
100
- permissionId: [],
101
- achieveType: "INTENT",
70
+ }
71
+ // 情况3: 其他类型,报错
72
+ else {
73
+ throw new ToolInputError(`itemIds must be an array or a JSON string, got ${typeof params.itemIds}`);
74
+ }
75
+ // 验证数组非空
76
+ if (!itemIds || itemIds.length === 0) {
77
+ throw new ToolInputError("itemIds array cannot be empty");
78
+ }
79
+ // Get WebSocket manager
80
+ const wsManager = getCachedXYWebSocketManager();
81
+ // Build DeleteCollection command
82
+ const command = {
83
+ header: {
84
+ namespace: "Common",
85
+ name: "Action",
86
+ },
87
+ payload: {
88
+ cardParam: {},
89
+ executeParam: {
90
+ executeMode: "background",
91
+ intentName: "DeleteCollection",
92
+ bundleName: "com.huawei.hmos.vassistant",
93
+ needUnlock: true,
94
+ actionResponse: true,
95
+ appType: "OHOS_APP",
96
+ timeOut: 5,
97
+ intentParam: {
98
+ itemIds,
102
99
  },
103
- responses: [
104
- {
105
- resultCode: "",
106
- displayText: "",
107
- ttsText: "",
108
- },
109
- ],
110
- needUploadResult: true,
111
- noHalfPage: false,
112
- pageControlRelated: false,
100
+ permissionId: [],
101
+ achieveType: "INTENT",
113
102
  },
114
- };
115
- // Send command and wait for response (60 second timeout)
116
- return new Promise((resolve, reject) => {
117
- const timeout = setTimeout(() => {
118
- wsManager.off("data-event", handler);
119
- logger.error("超时: 删除小艺收藏超时(60秒)", { toolCallId });
120
- reject(new Error("删除小艺收藏超时(60秒)"));
121
- }, 60000);
122
- // Listen for data events from WebSocket
123
- const handler = (event) => {
124
- if (event.intentName === "DeleteCollection") {
125
- clearTimeout(timeout);
126
- wsManager.off("data-event", handler);
127
- if (event.status === "success" && event.outputs) {
128
- resolve({
129
- content: [
130
- {
131
- type: "text",
132
- text: JSON.stringify(event.outputs),
133
- }
134
- ]
135
- });
136
- }
137
- else {
138
- reject(new Error(`删除小艺收藏失败: ${JSON.stringify(event.outputs)}`));
139
- }
140
- }
141
- };
142
- // Register event handler
143
- wsManager.on("data-event", handler);
144
- // Send the command
145
- const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
146
- sendCommand({
147
- config,
148
- sessionId,
149
- taskId: currentTaskId,
150
- messageId,
151
- command,
152
- toolCallId,
153
- })
154
- .then(() => {
155
- })
156
- .catch((error) => {
103
+ responses: [
104
+ {
105
+ resultCode: "",
106
+ displayText: "",
107
+ ttsText: "",
108
+ },
109
+ ],
110
+ needUploadResult: true,
111
+ noHalfPage: false,
112
+ pageControlRelated: false,
113
+ },
114
+ };
115
+ // Send command and wait for response (60 second timeout)
116
+ return new Promise((resolve, reject) => {
117
+ const timeout = setTimeout(() => {
118
+ wsManager.off("data-event", handler);
119
+ logger.error("超时: 删除小艺收藏超时(60秒)", { toolCallId });
120
+ reject(new Error("删除小艺收藏超时(60秒)"));
121
+ }, 60000);
122
+ // Listen for data events from WebSocket
123
+ const handler = (event) => {
124
+ if (event.intentName === "DeleteCollection") {
157
125
  clearTimeout(timeout);
158
126
  wsManager.off("data-event", handler);
159
- reject(error);
160
- });
127
+ if (event.status === "success" && event.outputs) {
128
+ resolve({
129
+ content: [
130
+ {
131
+ type: "text",
132
+ text: JSON.stringify(event.outputs),
133
+ }
134
+ ]
135
+ });
136
+ }
137
+ else {
138
+ reject(new Error(`删除小艺收藏失败: ${JSON.stringify(event.outputs)}`));
139
+ }
140
+ }
141
+ };
142
+ // Register event handler
143
+ wsManager.on("data-event", handler);
144
+ // Send the command
145
+ sendCommand({
146
+ config,
147
+ sessionId,
148
+ taskId,
149
+ messageId,
150
+ command,
151
+ toolCallId,
152
+ })
153
+ .then(() => {
154
+ })
155
+ .catch((error) => {
156
+ clearTimeout(timeout);
157
+ wsManager.off("data-event", handler);
158
+ reject(error);
161
159
  });
162
- },
163
- };
164
- }
160
+ });
161
+ },
162
+ };
@@ -1,7 +1,21 @@
1
- import type { SessionContext } from "./session-manager.js";
2
1
  /**
3
2
  * XiaoYi GUI tool - executes phone app interactions through GUI agent.
4
3
  * Simulates user interactions on phone screen (click, swipe, input, navigation, etc.)
5
4
  * to complete tasks that cannot be done through internet APIs.
6
5
  */
7
- export declare function createXiaoyiGuiTool(ctx: SessionContext): any;
6
+ export declare const xiaoyiGuiTool: {
7
+ name: string;
8
+ label: string;
9
+ description: string;
10
+ parameters: {
11
+ type: string;
12
+ properties: {
13
+ query: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ };
18
+ required: string[];
19
+ };
20
+ execute(toolCallId: string, params: any): Promise<unknown>;
21
+ };