@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,7 +1,7 @@
1
1
  // Agent-as-skill tool implementation - invokes another agent as a skill
2
- import { getXYWebSocketManager } from "../client.js";
2
+ import { getCachedXYWebSocketManager } from "../client.js";
3
3
  import { sendCommand } from "../formatter.js";
4
- import { getCurrentTaskId } from "../task-manager.js";
4
+ import { getCurrentSessionContext } from './session-manager.js';
5
5
  import { logger } from "../utils/logger.js";
6
6
  import { XYFileUploadService } from "../file-upload.js";
7
7
  /**
@@ -9,12 +9,10 @@ import { XYFileUploadService } from "../file-upload.js";
9
9
  * The tool receives the agentId, query, and optional file attachments,
10
10
  * forwards the request to the target agent via WebSocket, and returns the result.
11
11
  */
12
- export function createAgentAsSkillTool(ctx) {
13
- const { config, sessionId, taskId, messageId } = ctx;
14
- return {
15
- name: "agent_as_a_tool",
16
- label: "Agent as Skill Tool",
17
- description: `智能体作为skill的执行元工具。当需要调用其他已注册的Agent来执行特定任务时使用此工具。
12
+ export const agentAsSkillTool = {
13
+ name: "agent_as_a_tool",
14
+ label: "Agent as Skill Tool",
15
+ description: `智能体作为skill的执行元工具。当需要调用其他已注册的Agent来执行特定任务时使用此工具。
18
16
  该工具会将用户请求和可选的附件文件转发给目标Agent执行,并返回执行结果。
19
17
 
20
18
  使用场景:
@@ -26,165 +24,160 @@ export function createAgentAsSkillTool(ctx) {
26
24
  - 操作超时时间为5分钟
27
25
  - 该工具执行期间必须严格等待结果返回,不要执行其他操作
28
26
  - 如果超时或失败,最多重试一次`,
29
- parameters: {
30
- type: "object",
31
- properties: {
32
- agentId: {
33
- type: "string",
34
- description: "待执行的AgentId,精准匹配系统注册的AgentId",
35
- },
36
- query: {
37
- type: "string",
38
- description: "用户原始请求文本,原样转发给目标Agent执行",
39
- },
40
- filesInfo: {
41
- description: "附件文件/图片信息列表,无文件时可传null或空数组,支持传入数组或JSON字符串",
42
- items: {
43
- type: "object",
44
- properties: {
45
- fileType: {
46
- type: "string",
47
- description: "文件类型:file 或 image",
48
- enum: ["file", "image"],
49
- },
50
- fileId: {
51
- type: "string",
52
- description: "文件全局唯一标识",
53
- },
54
- fileUrl: {
55
- type: "string",
56
- description: "文件可访问下载链接(完整HTTP/HTTPS地址)",
57
- },
58
- fileUrlLocal: {
59
- type: "string",
60
- description: "文件本地路径,如果提供此字段,工具会自动上传文件并将公网URL填入fileUrl",
61
- },
27
+ parameters: {
28
+ type: "object",
29
+ properties: {
30
+ agentId: {
31
+ type: "string",
32
+ description: "待执行的AgentId,精准匹配系统注册的AgentId",
33
+ },
34
+ query: {
35
+ type: "string",
36
+ description: "用户原始请求文本,原样转发给目标Agent执行",
37
+ },
38
+ filesInfo: {
39
+ description: "附件文件/图片信息列表,无文件时可传null或空数组,支持传入数组或JSON字符串",
40
+ items: {
41
+ type: "object",
42
+ properties: {
43
+ fileType: {
44
+ type: "string",
45
+ description: "文件类型:file 或 image",
46
+ enum: ["file", "image"],
47
+ },
48
+ fileId: {
49
+ type: "string",
50
+ description: "文件全局唯一标识",
51
+ },
52
+ fileUrl: {
53
+ type: "string",
54
+ description: "文件可访问下载链接(完整HTTP/HTTPS地址)或文件本地路径。若为本地路径,工具会自动上传文件并替换为公网URL",
62
55
  },
63
56
  },
64
57
  },
65
58
  },
66
- required: ["agentId", "query"],
67
59
  },
68
- async execute(toolCallId, params) {
69
- // Dynamic lookup: use latest taskId from task-manager (handles steer/interrupt)
70
- const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
71
- // Validate parameters
72
- if (!params.agentId || typeof params.agentId !== "string") {
73
- throw new Error("Missing or invalid required parameter: agentId must be a non-empty string");
60
+ required: ["agentId", "query"],
61
+ },
62
+ async execute(toolCallId, params) {
63
+ const _c = getCurrentSessionContext();
64
+ const { config, sessionId, taskId, messageId } = _c;
65
+ // Dynamic lookup: use latest taskId from task-manager (handles steer/interrupt)
66
+ // Validate parameters
67
+ if (!params.agentId || typeof params.agentId !== "string") {
68
+ throw new Error("Missing or invalid required parameter: agentId must be a non-empty string");
69
+ }
70
+ if (!params.query || typeof params.query !== "string") {
71
+ throw new Error("Missing or invalid required parameter: query must be a non-empty string");
72
+ }
73
+ // Robust parsing: normalize filesInfo from array or JSON string
74
+ let filesInfo = null;
75
+ if (params.filesInfo) {
76
+ if (Array.isArray(params.filesInfo)) {
77
+ filesInfo = params.filesInfo;
74
78
  }
75
- if (!params.query || typeof params.query !== "string") {
76
- throw new Error("Missing or invalid required parameter: query must be a non-empty string");
77
- }
78
- // Robust parsing: normalize filesInfo from array or JSON string
79
- let filesInfo = null;
80
- if (params.filesInfo) {
81
- if (Array.isArray(params.filesInfo)) {
82
- filesInfo = params.filesInfo;
83
- }
84
- else if (typeof params.filesInfo === 'string') {
85
- try {
86
- const parsed = JSON.parse(params.filesInfo);
87
- if (Array.isArray(parsed)) {
88
- filesInfo = parsed;
89
- }
90
- else {
91
- throw new Error("filesInfo must be an array or a JSON string representing an array");
92
- }
79
+ else if (typeof params.filesInfo === 'string') {
80
+ try {
81
+ const parsed = JSON.parse(params.filesInfo);
82
+ if (Array.isArray(parsed)) {
83
+ filesInfo = parsed;
93
84
  }
94
- catch (parseError) {
95
- throw new Error(`filesInfo JSON解析失败: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
85
+ else {
86
+ throw new Error("filesInfo must be an array or a JSON string representing an array");
96
87
  }
97
88
  }
98
- else {
99
- filesInfo = null;
89
+ catch (parseError) {
90
+ throw new Error(`filesInfo JSON解析失败: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
100
91
  }
101
92
  }
102
- // Upload local files and fill fileUrl
103
- if (filesInfo && filesInfo.length > 0) {
104
- const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
105
- for (const fileInfo of filesInfo) {
106
- if (fileInfo.fileUrlLocal && !fileInfo.fileUrl) {
107
- try {
108
- const publicUrl = await uploadService.uploadFileAndGetUrl(fileInfo.fileUrlLocal, "TEMPORARY_MATERIAL_DOC");
109
- if (publicUrl) {
110
- fileInfo.fileUrl = publicUrl;
111
- }
112
- else {
113
- logger.warn("[AGENT-AS-SKILL] 上传文件未返回公网URL", { fileUrlLocal: fileInfo.fileUrlLocal });
114
- }
115
- }
116
- catch (uploadError) {
117
- logger.error("[AGENT-AS-SKILL] 上传本地文件失败", { fileUrlLocal: fileInfo.fileUrlLocal, error: uploadError });
118
- throw new Error(`上传本地文件失败 (${fileInfo.fileUrlLocal}): ${uploadError instanceof Error ? uploadError.message : String(uploadError)}`);
119
- }
120
- }
121
- // Remove fileUrlLocal from the final payload
122
- delete fileInfo.fileUrlLocal;
123
- }
93
+ else {
94
+ filesInfo = null;
124
95
  }
125
- // Get WebSocket manager
126
- const wsManager = getXYWebSocketManager(config);
127
- // Build ExecuteAgentAsSkill command
128
- const command = {
129
- header: {
130
- namespace: "System",
131
- name: "ExecuteAgentAsSkill",
132
- },
133
- payload: {
134
- agentId: params.agentId,
135
- query: params.query,
136
- filesInfo: filesInfo || null,
137
- },
138
- };
139
- // Send command and wait for response (5 minute timeout)
140
- return new Promise((resolve, reject) => {
141
- const timeout = setTimeout(() => {
142
- wsManager.off("agent-as-skill-response", handler);
143
- logger.error("超时: Agent-as-Skill 操作超时(5分钟)", { agentId: params.agentId, toolCallId });
144
- reject(new Error("Agent-as-Skill 操作超时(5分钟)"));
145
- }, 300000); // 5 minutes timeout
146
- // Listen for Agent-as-Skill response events
147
- const handler = (event) => {
148
- // Check if this is the ExecuteAgentAsSkillResponse we're waiting for
149
- if (event.header?.namespace === "System" &&
150
- event.header?.name === "ExecuteAgentAsSkillResponse") {
151
- clearTimeout(timeout);
152
- wsManager.off("agent-as-skill-response", handler);
153
- // Return the payload directly as the tool result
154
- const payload = event.payload;
155
- if (payload) {
156
- resolve({
157
- content: [
158
- {
159
- type: "text",
160
- text: typeof payload === "string" ? payload : JSON.stringify(payload),
161
- },
162
- ],
163
- });
96
+ }
97
+ // Upload local files and fill fileUrl
98
+ if (filesInfo && filesInfo.length > 0) {
99
+ const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
100
+ for (const fileInfo of filesInfo) {
101
+ if (fileInfo.fileUrl && !/^https?:\/\//i.test(fileInfo.fileUrl)) {
102
+ const localPath = fileInfo.fileUrl;
103
+ try {
104
+ const publicUrl = await uploadService.uploadFileAndGetUrl(localPath, "TEMPORARY_MATERIAL_DOC");
105
+ if (publicUrl) {
106
+ fileInfo.fileUrl = publicUrl;
164
107
  }
165
108
  else {
166
- reject(new Error("Agent-as-Skill 响应格式错误:缺少 payload"));
109
+ logger.warn("[AGENT-AS-SKILL] 上传文件未返回公网URL", { localPath });
167
110
  }
168
111
  }
169
- };
170
- // Register event handler
171
- wsManager.on("agent-as-skill-response", handler);
172
- // Send the command
173
- sendCommand({
174
- config,
175
- sessionId,
176
- taskId: currentTaskId,
177
- messageId,
178
- command,
179
- toolCallId,
180
- }).then(() => {
181
- logger.log("[AGENT-AS-SKILL] Command sent successfully", { agentId: params.agentId });
182
- }).catch((error) => {
112
+ catch (uploadError) {
113
+ logger.error("[AGENT-AS-SKILL] 上传本地文件失败", { localPath, error: uploadError });
114
+ throw new Error(`上传本地文件失败 (${localPath}): ${uploadError instanceof Error ? uploadError.message : String(uploadError)}`);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ // Get WebSocket manager
120
+ const wsManager = getCachedXYWebSocketManager();
121
+ // Build ExecuteAgentAsSkill command
122
+ const command = {
123
+ header: {
124
+ namespace: "System",
125
+ name: "ExecuteAgentAsSkill",
126
+ },
127
+ payload: {
128
+ agentId: params.agentId,
129
+ query: params.query,
130
+ filesInfo: filesInfo || null,
131
+ },
132
+ };
133
+ // Send command and wait for response (5 minute timeout)
134
+ return new Promise((resolve, reject) => {
135
+ const timeout = setTimeout(() => {
136
+ wsManager.off("agent-as-skill-response", handler);
137
+ logger.error("超时: Agent-as-Skill 操作超时(5分钟)", { agentId: params.agentId, toolCallId });
138
+ reject(new Error("Agent-as-Skill 操作超时(5分钟)"));
139
+ }, 300000); // 5 minutes timeout
140
+ // Listen for Agent-as-Skill response events
141
+ const handler = (event) => {
142
+ // Check if this is the ExecuteAgentAsSkillResponse we're waiting for
143
+ if (event.header?.namespace === "System" &&
144
+ event.header?.name === "ExecuteAgentAsSkillResponse") {
183
145
  clearTimeout(timeout);
184
146
  wsManager.off("agent-as-skill-response", handler);
185
- reject(error);
186
- });
147
+ // Return the payload directly as the tool result
148
+ const payload = event.payload;
149
+ if (payload) {
150
+ resolve({
151
+ content: [
152
+ {
153
+ type: "text",
154
+ text: typeof payload === "string" ? payload : JSON.stringify(payload),
155
+ },
156
+ ],
157
+ });
158
+ }
159
+ else {
160
+ reject(new Error("Agent-as-Skill 响应格式错误:缺少 payload"));
161
+ }
162
+ }
163
+ };
164
+ // Register event handler
165
+ wsManager.on("agent-as-skill-response", handler);
166
+ // Send the command
167
+ sendCommand({
168
+ config,
169
+ sessionId,
170
+ taskId,
171
+ messageId,
172
+ command,
173
+ toolCallId,
174
+ }).then(() => {
175
+ logger.log("[AGENT-AS-SKILL] Command sent successfully", { agentId: params.agentId });
176
+ }).catch((error) => {
177
+ clearTimeout(timeout);
178
+ wsManager.off("agent-as-skill-response", handler);
179
+ reject(error);
187
180
  });
188
- },
189
- };
190
- }
181
+ });
182
+ },
183
+ };
@@ -1,7 +1,29 @@
1
- import type { SessionContext } from "./session-manager.js";
2
1
  /**
3
2
  * XY calendar event tool - creates a calendar event on user's device.
4
3
  * Requires title, dtStart (start time), and dtEnd (end time) parameters.
5
4
  * Time format must be: yyyy-mm-dd hh:mm:ss
6
5
  */
7
- export declare function createCalendarTool(ctx: SessionContext): any;
6
+ export declare const calendarTool: {
7
+ name: string;
8
+ label: string;
9
+ description: string;
10
+ parameters: {
11
+ type: string;
12
+ properties: {
13
+ title: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ dtStart: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ dtEnd: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ };
26
+ required: string[];
27
+ };
28
+ execute(toolCallId: string, params: any): Promise<unknown>;
29
+ };
@@ -1,135 +1,133 @@
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
  * XY calendar event tool - creates a calendar event on user's device.
7
7
  * Requires title, dtStart (start time), and dtEnd (end time) parameters.
8
8
  * Time format must be: yyyy-mm-dd hh:mm:ss
9
9
  */
10
- export function createCalendarTool(ctx) {
11
- const { config, sessionId, taskId, messageId } = ctx;
12
- return {
13
- name: "create_calendar_event",
14
- label: "Create Calendar Event",
15
- description: `在用户设备上创建日程。需要提供日程标题、开始时间和结束时间。时间格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)。注意:该工具执行时间较长(最多60秒),请勿重复调用,超时或失败时最多重试一次。
10
+ export const calendarTool = {
11
+ name: "create_calendar_event",
12
+ label: "Create Calendar Event",
13
+ description: `在用户设备上创建日程。需要提供日程标题、开始时间和结束时间。时间格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)。注意:该工具执行时间较长(最多60秒),请勿重复调用,超时或失败时最多重试一次。
16
14
  注意事项:使用该工具之前需获取当前真实时间
17
15
 
18
16
  回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
19
17
  `,
20
- parameters: {
21
- type: "object",
22
- properties: {
23
- title: {
24
- type: "string",
25
- description: "日程标题/名称",
26
- },
27
- dtStart: {
28
- type: "string",
29
- description: "日程开始时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)",
30
- },
31
- dtEnd: {
32
- type: "string",
33
- description: "日程结束时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 17:30:00)",
34
- },
18
+ parameters: {
19
+ type: "object",
20
+ properties: {
21
+ title: {
22
+ type: "string",
23
+ description: "日程标题/名称",
24
+ },
25
+ dtStart: {
26
+ type: "string",
27
+ description: "日程开始时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)",
28
+ },
29
+ dtEnd: {
30
+ type: "string",
31
+ description: "日程结束时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 17:30:00)",
35
32
  },
36
- required: ["title", "dtStart", "dtEnd"],
37
33
  },
38
- async execute(toolCallId, params) {
39
- // Validate parameters
40
- if (!params.title || !params.dtStart || !params.dtEnd) {
41
- throw new Error("Missing required parameters: title, dtStart, and dtEnd are required");
42
- }
43
- // Convert time strings to millisecond timestamps
44
- const dtStartMs = new Date(params.dtStart).getTime();
45
- const dtEndMs = new Date(params.dtEnd).getTime();
46
- if (isNaN(dtStartMs) || isNaN(dtEndMs)) {
47
- throw new Error("Invalid time format. Required format: yyyy-mm-dd hh:mm:ss (e.g., 2024-01-15 14:30:00)");
48
- }
49
- // Get WebSocket manager
50
- const wsManager = getXYWebSocketManager(config);
51
- // Build CreateCalendarEvent command
52
- const command = {
53
- header: {
54
- namespace: "Common",
55
- name: "ActionAndResult",
56
- },
57
- payload: {
58
- cardParam: {},
59
- executeParam: {
60
- executeMode: "background",
61
- intentName: "CreateCalendarEvent",
62
- bundleName: "com.huawei.hmos.calendardata",
63
- dimension: "",
64
- needUnlock: true,
65
- actionResponse: true,
66
- timeOut: 5,
67
- intentParam: {
68
- title: params.title,
69
- dtStart: dtStartMs,
70
- dtEnd: dtEndMs,
71
- },
72
- achieveType: "INTENT",
34
+ required: ["title", "dtStart", "dtEnd"],
35
+ },
36
+ async execute(toolCallId, params) {
37
+ const _c = getCurrentSessionContext();
38
+ const { config, sessionId, taskId, messageId } = _c;
39
+ // Validate parameters
40
+ if (!params.title || !params.dtStart || !params.dtEnd) {
41
+ throw new Error("Missing required parameters: title, dtStart, and dtEnd are required");
42
+ }
43
+ // Convert time strings to millisecond timestamps
44
+ const dtStartMs = new Date(params.dtStart).getTime();
45
+ const dtEndMs = new Date(params.dtEnd).getTime();
46
+ if (isNaN(dtStartMs) || isNaN(dtEndMs)) {
47
+ throw new Error("Invalid time format. Required format: yyyy-mm-dd hh:mm:ss (e.g., 2024-01-15 14:30:00)");
48
+ }
49
+ // Get WebSocket manager
50
+ const wsManager = getCachedXYWebSocketManager();
51
+ // Build CreateCalendarEvent command
52
+ const command = {
53
+ header: {
54
+ namespace: "Common",
55
+ name: "ActionAndResult",
56
+ },
57
+ payload: {
58
+ cardParam: {},
59
+ executeParam: {
60
+ executeMode: "background",
61
+ intentName: "CreateCalendarEvent",
62
+ bundleName: "com.huawei.hmos.calendardata",
63
+ dimension: "",
64
+ needUnlock: true,
65
+ actionResponse: true,
66
+ timeOut: 5,
67
+ intentParam: {
68
+ title: params.title,
69
+ dtStart: dtStartMs,
70
+ dtEnd: dtEndMs,
73
71
  },
74
- responses: [
75
- {
76
- resultCode: "",
77
- displayText: "",
78
- ttsText: "",
79
- },
80
- ],
81
- needUploadResult: true,
82
- noHalfPage: false,
83
- pageControlRelated: false,
72
+ achieveType: "INTENT",
84
73
  },
85
- };
86
- // Send command and wait for response (60 second timeout)
87
- return new Promise((resolve, reject) => {
88
- const timeout = setTimeout(() => {
89
- wsManager.off("data-event", handler);
90
- logger.error("超时: 创建日程超时(60秒)", { toolCallId });
91
- reject(new Error("创建日程超时(60秒)"));
92
- }, 60000);
93
- // Listen for data events from WebSocket
94
- const handler = (event) => {
95
- if (event.intentName === "CreateCalendarEvent") {
96
- clearTimeout(timeout);
97
- wsManager.off("data-event", handler);
98
- if (event.status === "success" && event.outputs) {
99
- resolve({
100
- content: [
101
- {
102
- type: "text",
103
- text: JSON.stringify(event.outputs),
104
- },
105
- ],
106
- });
107
- }
108
- else {
109
- reject(new Error(`创建日程失败: ${JSON.stringify(event.outputs)}`));
110
- }
111
- }
112
- };
113
- // Register event handler
114
- wsManager.on("data-event", handler);
115
- // Send the command
116
- const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
117
- sendCommand({
118
- config,
119
- sessionId,
120
- taskId: currentTaskId,
121
- messageId,
122
- command,
123
- toolCallId,
124
- })
125
- .then(() => {
126
- })
127
- .catch((error) => {
74
+ responses: [
75
+ {
76
+ resultCode: "",
77
+ displayText: "",
78
+ ttsText: "",
79
+ },
80
+ ],
81
+ needUploadResult: true,
82
+ noHalfPage: false,
83
+ pageControlRelated: false,
84
+ },
85
+ };
86
+ // Send command and wait for response (60 second timeout)
87
+ return new Promise((resolve, reject) => {
88
+ const timeout = setTimeout(() => {
89
+ wsManager.off("data-event", handler);
90
+ logger.error("超时: 创建日程超时(60秒)", { toolCallId });
91
+ reject(new Error("创建日程超时(60秒)"));
92
+ }, 60000);
93
+ // Listen for data events from WebSocket
94
+ const handler = (event) => {
95
+ if (event.intentName === "CreateCalendarEvent") {
128
96
  clearTimeout(timeout);
129
97
  wsManager.off("data-event", handler);
130
- reject(error);
131
- });
98
+ if (event.status === "success" && event.outputs) {
99
+ resolve({
100
+ content: [
101
+ {
102
+ type: "text",
103
+ text: JSON.stringify(event.outputs),
104
+ },
105
+ ],
106
+ });
107
+ }
108
+ else {
109
+ reject(new Error(`创建日程失败: ${JSON.stringify(event.outputs)}`));
110
+ }
111
+ }
112
+ };
113
+ // Register event handler
114
+ wsManager.on("data-event", handler);
115
+ // Send the command
116
+ sendCommand({
117
+ config,
118
+ sessionId,
119
+ taskId,
120
+ messageId,
121
+ command,
122
+ toolCallId,
123
+ })
124
+ .then(() => {
125
+ })
126
+ .catch((error) => {
127
+ clearTimeout(timeout);
128
+ wsManager.off("data-event", handler);
129
+ reject(error);
132
130
  });
133
- },
134
- };
135
- }
131
+ });
132
+ },
133
+ };
@@ -1,6 +1,20 @@
1
- import type { SessionContext } from "./session-manager.js";
2
- /**
3
- * call_device_tool - 通用端工具调度器。
4
- * LLM 必须先通过 get_xxx_tool_schema 获取具体工具 schema,再用本工具执行。
5
- */
6
- export declare function createCallDeviceTool(ctx: SessionContext): any;
1
+ export declare const callDeviceTool: {
2
+ name: string;
3
+ label: string;
4
+ description: string;
5
+ parameters: {
6
+ type: string;
7
+ properties: {
8
+ toolName: {
9
+ type: string;
10
+ description: string;
11
+ };
12
+ arguments: {
13
+ type: string;
14
+ description: string;
15
+ };
16
+ };
17
+ required: string[];
18
+ };
19
+ execute(toolCallId: string, params: any): Promise<any>;
20
+ };