@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,153 +1,131 @@
1
- import { createNoteTool } from "./note-tool.js";
2
- import { createSearchNoteTool } from "./search-note-tool.js";
3
- import { createModifyNoteTool } from "./modify-note-tool.js";
4
- import { makeAlarmTool } from "./create-alarm-tool.js";
5
- import { createSearchAlarmTool } from "./search-alarm-tool.js";
6
- import { createModifyAlarmTool } from "./modify-alarm-tool.js";
7
- import { createDeleteAlarmTool } from "./delete-alarm-tool.js";
8
- import { createSearchContactTool } from "./search-contact-tool.js";
9
- import { createCallPhoneTool } from "./call-phone-tool.js";
10
- import { createSearchMessageTool } from "./search-message-tool.js";
11
- import { createSendMessageTool } from "./send-message-tool.js";
12
- import { createXiaoyiAddCollectionTool } from "./xiaoyi-add-collection-tool.js";
13
- import { createXiaoyiCollectionTool } from "./xiaoyi-collection-tool.js";
14
- import { createXiaoyiDeleteCollectionTool } from "./xiaoyi-delete-collection-tool.js";
15
- import { createCalendarTool } from "./calendar-tool.js";
16
- import { createSearchCalendarTool } from "./search-calendar-tool.js";
17
- import { createSearchPhotoGalleryTool } from "./search-photo-gallery-tool.js";
18
- import { createUploadPhotoTool } from "./upload-photo-tool.js";
19
- import { createSaveMediaToGalleryTool } from "./save-media-to-gallery-tool.js";
20
- import { createSearchFileTool } from "./search-file-tool.js";
21
- import { createUploadFileTool } from "./upload-file-tool.js";
22
- import { createSaveFileToPhoneTool } from "./save-file-to-phone-tool.js";
23
- import { createSendEmailTool } from "./send-email-tool.js";
24
- import { createSearchEmailTool } from "./search-email-tool.js";
1
+ import { noteTool } from "./note-tool.js";
2
+ import { searchNoteTool } from "./search-note-tool.js";
3
+ import { modifyNoteTool } from "./modify-note-tool.js";
4
+ import { createAlarmTool } from "./create-alarm-tool.js";
5
+ import { searchAlarmTool } from "./search-alarm-tool.js";
6
+ import { modifyAlarmTool } from "./modify-alarm-tool.js";
7
+ import { deleteAlarmTool } from "./delete-alarm-tool.js";
8
+ import { searchContactTool } from "./search-contact-tool.js";
9
+ import { callPhoneTool } from "./call-phone-tool.js";
10
+ import { searchMessageTool } from "./search-message-tool.js";
11
+ import { sendMessageTool } from "./send-message-tool.js";
12
+ import { xiaoyiAddCollectionTool } from "./xiaoyi-add-collection-tool.js";
13
+ import { xiaoyiCollectionTool } from "./xiaoyi-collection-tool.js";
14
+ import { xiaoyiDeleteCollectionTool } from "./xiaoyi-delete-collection-tool.js";
15
+ import { calendarTool } from "./calendar-tool.js";
16
+ import { searchCalendarTool } from "./search-calendar-tool.js";
17
+ import { searchPhotoGalleryTool } from "./search-photo-gallery-tool.js";
18
+ import { uploadPhotoTool } from "./upload-photo-tool.js";
19
+ import { saveMediaToGalleryTool } from "./save-media-to-gallery-tool.js";
20
+ import { searchFileTool } from "./search-file-tool.js";
21
+ import { uploadFileTool } from "./upload-file-tool.js";
22
+ import { saveFileToPhoneTool } from "./save-file-to-phone-tool.js";
23
+ import { sendEmailTool } from "./send-email-tool.js";
24
+ import { searchEmailTool } from "./search-email-tool.js";
25
+ import { getCachedXYWebSocketManager } from "../client.js";
25
26
  import { sendStatusUpdate } from "../formatter.js";
26
- import { getCurrentTaskId, getCurrentMessageId } from "../task-manager.js";
27
+ import { getCurrentSessionContext } from './session-manager.js';
27
28
  /**
28
29
  * call_device_tool - 通用端工具调度器。
29
30
  * LLM 必须先通过 get_xxx_tool_schema 获取具体工具 schema,再用本工具执行。
30
31
  */
31
- export function createCallDeviceTool(ctx) {
32
- const { config, sessionId, taskId, messageId } = ctx;
33
- const noteTool = createNoteTool(ctx);
34
- const modifyNoteTool = createModifyNoteTool(ctx);
35
- const createAlarmTool = makeAlarmTool(ctx);
36
- const modifyAlarmTool = createModifyAlarmTool(ctx);
37
- const deleteAlarmTool = createDeleteAlarmTool(ctx);
38
- const callPhoneTool = createCallPhoneTool(ctx);
39
- const calendarTool = createCalendarTool(ctx);
40
- const searchNoteTool = createSearchNoteTool(ctx);
41
- const searchMessageTool = createSearchMessageTool(ctx);
42
- const sendMessageTool = createSendMessageTool(ctx);
43
- const xiaoyiAddCollectionTool = createXiaoyiAddCollectionTool(ctx);
44
- const xiaoyiCollectionTool = createXiaoyiCollectionTool(ctx);
45
- const xiaoyiDeleteCollectionTool = createXiaoyiDeleteCollectionTool(ctx);
46
- const searchPhotoGalleryTool = createSearchPhotoGalleryTool(ctx);
47
- const uploadPhotoTool = createUploadPhotoTool(ctx);
48
- const uploadFileTool = createUploadFileTool(ctx);
49
- const sendEmailTool = createSendEmailTool(ctx);
50
- const searchAlarmTool = createSearchAlarmTool(ctx);
51
- const searchContactTool = createSearchContactTool(ctx);
52
- const searchCalendarTool = createSearchCalendarTool(ctx);
53
- const saveMediaToGalleryTool = createSaveMediaToGalleryTool(ctx);
54
- const searchFileTool = createSearchFileTool(ctx);
55
- const saveFileToPhoneTool = createSaveFileToPhoneTool(ctx);
56
- const searchEmailTool = createSearchEmailTool(ctx);
57
- /**
58
- * 端工具注册表 —— 按 name 索引所有可通过 call_device_tool 调度的工具。
59
- */
60
- const deviceToolRegistry = new Map([
61
- [noteTool.name, noteTool],
62
- [searchNoteTool.name, searchNoteTool],
63
- [modifyNoteTool.name, modifyNoteTool],
64
- [createAlarmTool.name, createAlarmTool],
65
- [searchAlarmTool.name, searchAlarmTool],
66
- [modifyAlarmTool.name, modifyAlarmTool],
67
- [deleteAlarmTool.name, deleteAlarmTool],
68
- [searchContactTool.name, searchContactTool],
69
- [callPhoneTool.name, callPhoneTool],
70
- [searchMessageTool.name, searchMessageTool],
71
- [sendMessageTool.name, sendMessageTool],
72
- [xiaoyiAddCollectionTool.name, xiaoyiAddCollectionTool],
73
- [xiaoyiCollectionTool.name, xiaoyiCollectionTool],
74
- [xiaoyiDeleteCollectionTool.name, xiaoyiDeleteCollectionTool],
75
- [calendarTool.name, calendarTool],
76
- [searchCalendarTool.name, searchCalendarTool],
77
- [searchPhotoGalleryTool.name, searchPhotoGalleryTool],
78
- [uploadPhotoTool.name, uploadPhotoTool],
79
- [saveMediaToGalleryTool.name, saveMediaToGalleryTool],
80
- [searchFileTool.name, searchFileTool],
81
- [uploadFileTool.name, uploadFileTool],
82
- [saveFileToPhoneTool.name, saveFileToPhoneTool],
83
- [sendEmailTool.name, sendEmailTool],
84
- [searchEmailTool.name, searchEmailTool],
85
- ]);
86
- return {
87
- name: "call_device_tool",
88
- label: "Call Device Tool",
89
- description: "用户设备侧工具调用。必须先调用get_xxx_tool_schema获取了具体的工具schema,才能使用本工具执行对应设备侧工具。",
90
- parameters: {
91
- type: "object",
92
- properties: {
93
- toolName: {
94
- type: "string",
95
- description: "要调用的具体端工具名称,即get_xxx_tool_schema返回的工具的name",
96
- },
97
- arguments: {
98
- type: "object",
99
- description: "工具所需的具体参数JSON键值对",
100
- },
32
+ /**
33
+ * 端工具注册表 —— name 索引所有可通过 call_device_tool 调度的工具。
34
+ */
35
+ const deviceToolRegistry = new Map([
36
+ [noteTool.name, noteTool],
37
+ [searchNoteTool.name, searchNoteTool],
38
+ [modifyNoteTool.name, modifyNoteTool],
39
+ [createAlarmTool.name, createAlarmTool],
40
+ [searchAlarmTool.name, searchAlarmTool],
41
+ [modifyAlarmTool.name, modifyAlarmTool],
42
+ [deleteAlarmTool.name, deleteAlarmTool],
43
+ [searchContactTool.name, searchContactTool],
44
+ [callPhoneTool.name, callPhoneTool],
45
+ [searchMessageTool.name, searchMessageTool],
46
+ [sendMessageTool.name, sendMessageTool],
47
+ [xiaoyiAddCollectionTool.name, xiaoyiAddCollectionTool],
48
+ [xiaoyiCollectionTool.name, xiaoyiCollectionTool],
49
+ [xiaoyiDeleteCollectionTool.name, xiaoyiDeleteCollectionTool],
50
+ [calendarTool.name, calendarTool],
51
+ [searchCalendarTool.name, searchCalendarTool],
52
+ [searchPhotoGalleryTool.name, searchPhotoGalleryTool],
53
+ [uploadPhotoTool.name, uploadPhotoTool],
54
+ [saveMediaToGalleryTool.name, saveMediaToGalleryTool],
55
+ [searchFileTool.name, searchFileTool],
56
+ [uploadFileTool.name, uploadFileTool],
57
+ [saveFileToPhoneTool.name, saveFileToPhoneTool],
58
+ [sendEmailTool.name, sendEmailTool],
59
+ [searchEmailTool.name, searchEmailTool],
60
+ ]);
61
+ export const callDeviceTool = {
62
+ name: "call_device_tool",
63
+ label: "Call Device Tool",
64
+ description: "用户设备侧工具调用。必须先调用get_xxx_tool_schema获取了具体的工具schema,才能使用本工具执行对应设备侧工具。",
65
+ parameters: {
66
+ type: "object",
67
+ properties: {
68
+ toolName: {
69
+ type: "string",
70
+ description: "要调用的具体端工具名称,即get_xxx_tool_schema返回的工具的name",
71
+ },
72
+ arguments: {
73
+ type: "object",
74
+ description: "工具所需的具体参数JSON键值对",
101
75
  },
102
- required: ["toolName", "arguments"],
103
76
  },
104
- async execute(toolCallId, params) {
105
- const { toolName, arguments: toolArgs } = params;
106
- // 向用户端发送具体工具名的状态更新
107
- const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
108
- const currentMessageId = getCurrentMessageId(sessionId) ?? messageId;
109
- try {
110
- await sendStatusUpdate({
111
- config,
112
- sessionId,
113
- taskId: currentTaskId,
114
- messageId: currentMessageId,
115
- text: `正在使用工具: ${toolName}...`,
116
- state: "working",
117
- });
118
- }
119
- catch (_) {
120
- // 状态更新失败不影响工具执行
121
- }
122
- const tool = deviceToolRegistry.get(toolName);
123
- if (!tool) {
77
+ required: ["toolName", "arguments"],
78
+ },
79
+ async execute(toolCallId, params) {
80
+ const ctx = getCurrentSessionContext();
81
+ const wsManager = getCachedXYWebSocketManager();
82
+ const config = wsManager.config;
83
+ const sessionId = ctx?.sessionId ?? "";
84
+ const taskId = ctx?.taskId ?? "";
85
+ const messageId = ctx?.messageId ?? "";
86
+ const { toolName, arguments: toolArgs } = params;
87
+ // 向用户端发送具体工具名的状态更新
88
+ try {
89
+ await sendStatusUpdate({
90
+ config,
91
+ sessionId,
92
+ taskId,
93
+ messageId,
94
+ text: `正在使用工具: ${toolName}...`,
95
+ state: "working",
96
+ });
97
+ }
98
+ catch (_) {
99
+ // 状态更新失败不影响工具执行
100
+ }
101
+ const tool = deviceToolRegistry.get(toolName);
102
+ if (!tool) {
103
+ return {
104
+ content: [
105
+ {
106
+ type: "text",
107
+ text: `端工具${toolName}不存在。请确保toolName为get_xxx_tool_schema返回的工具的name。`,
108
+ },
109
+ ],
110
+ };
111
+ }
112
+ try {
113
+ return await tool.execute(toolCallId, toolArgs);
114
+ }
115
+ catch (error) {
116
+ // ToolInputError (.name === "ToolInputError") 或其他参数校验错误
117
+ if (error.name === "ToolInputError") {
124
118
  return {
125
119
  content: [
126
120
  {
127
121
  type: "text",
128
- text: `端工具${toolName}不存在。请确保toolName为get_xxx_tool_schema返回的工具的name。`,
122
+ text: `端工具参数错误:${error.message}。请确保arguments符合get_xxx_tool_schema返回的工具schema。`,
129
123
  },
130
124
  ],
131
125
  };
132
126
  }
133
- try {
134
- return await tool.execute(toolCallId, toolArgs);
135
- }
136
- catch (error) {
137
- // ToolInputError (.name === "ToolInputError") 或其他参数校验错误
138
- if (error.name === "ToolInputError") {
139
- return {
140
- content: [
141
- {
142
- type: "text",
143
- text: `端工具参数错误:${error.message}。请确保arguments符合get_xxx_tool_schema返回的工具schema。`,
144
- },
145
- ],
146
- };
147
- }
148
- // 非参数错误(网络超时等),直接向上抛出
149
- throw error;
150
- }
151
- },
152
- };
153
- }
127
+ // 非参数错误(网络超时等),直接向上抛出
128
+ throw error;
129
+ }
130
+ },
131
+ };
@@ -1,6 +1,25 @@
1
- import type { SessionContext } from "./session-manager.js";
2
1
  /**
3
2
  * XY call phone tool - makes a phone call on user's device.
4
3
  * Requires phoneNumber parameter and optional slotId (0 for primary SIM, 1 for secondary SIM).
5
4
  */
6
- export declare function createCallPhoneTool(ctx: SessionContext): any;
5
+ export declare const callPhoneTool: {
6
+ name: string;
7
+ label: string;
8
+ description: string;
9
+ parameters: {
10
+ type: string;
11
+ properties: {
12
+ phoneNumber: {
13
+ type: string;
14
+ description: string;
15
+ };
16
+ slotId: {
17
+ type: string;
18
+ description: string;
19
+ default: number;
20
+ };
21
+ };
22
+ required: string[];
23
+ };
24
+ execute(toolCallId: string, params: any): Promise<unknown>;
25
+ };
@@ -1,127 +1,125 @@
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 call phone tool - makes a phone call on user's device.
7
7
  * Requires phoneNumber parameter and optional slotId (0 for primary SIM, 1 for secondary SIM).
8
8
  */
9
- export function createCallPhoneTool(ctx) {
10
- const { config, sessionId, taskId, messageId } = ctx;
11
- return {
12
- name: "call_phone",
13
- label: "Call Phone",
14
- description: "拨打电话。需要提供要拨打的电话号码。slotId参数可选,默认为0(主卡),如果用户明确要求使用副卡则设置为1。注意:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。",
15
- parameters: {
16
- type: "object",
17
- properties: {
18
- phoneNumber: {
19
- type: "string",
20
- description: "要拨打的电话号码",
21
- },
22
- slotId: {
23
- type: "number",
24
- description: "SIM卡槽ID,默认为0(主卡),设置为1表示副卡。仅当用户明确要求使用副卡时才设置为1",
25
- default: 0,
26
- },
9
+ export const callPhoneTool = {
10
+ name: "call_phone",
11
+ label: "Call Phone",
12
+ description: "拨打电话。需要提供要拨打的电话号码。slotId参数可选,默认为0(主卡),如果用户明确要求使用副卡则设置为1。注意:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。",
13
+ parameters: {
14
+ type: "object",
15
+ properties: {
16
+ phoneNumber: {
17
+ type: "string",
18
+ description: "要拨打的电话号码",
19
+ },
20
+ slotId: {
21
+ type: "number",
22
+ description: "SIM卡槽ID,默认为0(主卡),设置为1表示副卡。仅当用户明确要求使用副卡时才设置为1",
23
+ default: 0,
27
24
  },
28
- required: ["phoneNumber"],
29
25
  },
30
- async execute(toolCallId, params) {
31
- // Validate phoneNumber parameter
32
- if (!params.phoneNumber || typeof params.phoneNumber !== "string" || params.phoneNumber.trim() === "") {
33
- throw new Error("Missing required parameter: phoneNumber must be a non-empty string");
34
- }
35
- // Set default slotId if not provided
36
- const slotId = params.slotId !== undefined && params.slotId !== null ? params.slotId : 0;
37
- // Validate slotId (must be 0 or 1)
38
- if (slotId !== 0 && slotId !== 1) {
39
- throw new Error("Invalid slotId: must be 0 (primary SIM) or 1 (secondary SIM)");
40
- }
41
- // Get WebSocket manager
42
- const wsManager = getXYWebSocketManager(config);
43
- // Build StartCall command
44
- const command = {
45
- header: {
46
- namespace: "Common",
47
- name: "Action",
48
- },
49
- payload: {
50
- cardParam: {},
51
- executeParam: {
52
- executeMode: "background",
53
- intentName: "StartCall",
54
- bundleName: "com.huawei.hmos.aidispatchservice",
55
- dimension: "",
56
- needUnlock: true,
57
- actionResponse: true,
58
- timeOut: 5,
59
- intentParam: {
60
- phoneNumber: params.phoneNumber.trim(),
61
- slotId: slotId,
62
- },
63
- permissionId: [],
64
- achieveType: "INTENT",
26
+ required: ["phoneNumber"],
27
+ },
28
+ async execute(toolCallId, params) {
29
+ const _c = getCurrentSessionContext();
30
+ const { config, sessionId, taskId, messageId } = _c;
31
+ // Validate phoneNumber parameter
32
+ if (!params.phoneNumber || typeof params.phoneNumber !== "string" || params.phoneNumber.trim() === "") {
33
+ throw new Error("Missing required parameter: phoneNumber must be a non-empty string");
34
+ }
35
+ // Set default slotId if not provided
36
+ const slotId = params.slotId !== undefined && params.slotId !== null ? params.slotId : 0;
37
+ // Validate slotId (must be 0 or 1)
38
+ if (slotId !== 0 && slotId !== 1) {
39
+ throw new Error("Invalid slotId: must be 0 (primary SIM) or 1 (secondary SIM)");
40
+ }
41
+ // Get WebSocket manager
42
+ const wsManager = getCachedXYWebSocketManager();
43
+ // Build StartCall command
44
+ const command = {
45
+ header: {
46
+ namespace: "Common",
47
+ name: "Action",
48
+ },
49
+ payload: {
50
+ cardParam: {},
51
+ executeParam: {
52
+ executeMode: "background",
53
+ intentName: "StartCall",
54
+ bundleName: "com.huawei.hmos.aidispatchservice",
55
+ dimension: "",
56
+ needUnlock: true,
57
+ actionResponse: true,
58
+ timeOut: 5,
59
+ intentParam: {
60
+ phoneNumber: params.phoneNumber.trim(),
61
+ slotId: slotId,
65
62
  },
66
- responses: [
67
- {
68
- resultCode: "",
69
- displayText: "",
70
- ttsText: "",
71
- },
72
- ],
73
- needUploadResult: true,
74
- noHalfPage: false,
75
- pageControlRelated: false,
63
+ permissionId: [],
64
+ achieveType: "INTENT",
76
65
  },
77
- };
78
- // Send command and wait for response (60 second timeout)
79
- return new Promise((resolve, reject) => {
80
- const timeout = setTimeout(() => {
81
- wsManager.off("data-event", handler);
82
- logger.error("超时: 拨打电话超时(60秒)", { toolCallId });
83
- reject(new Error("拨打电话超时(60秒)"));
84
- }, 60000);
85
- // Listen for data events from WebSocket
86
- const handler = (event) => {
87
- if (event.intentName === "StartCall") {
88
- clearTimeout(timeout);
89
- wsManager.off("data-event", handler);
90
- if (event.status === "success" && event.outputs) {
91
- resolve({
92
- content: [
93
- {
94
- type: "text",
95
- text: JSON.stringify(event.outputs),
96
- },
97
- ],
98
- });
99
- }
100
- else {
101
- reject(new Error(`拨打电话失败: ${JSON.stringify(event.outputs)}`));
102
- }
103
- }
104
- };
105
- // Register event handler
106
- wsManager.on("data-event", handler);
107
- // Send the command
108
- const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
109
- sendCommand({
110
- config,
111
- sessionId,
112
- taskId: currentTaskId,
113
- messageId,
114
- command,
115
- toolCallId,
116
- })
117
- .then(() => {
118
- })
119
- .catch((error) => {
66
+ responses: [
67
+ {
68
+ resultCode: "",
69
+ displayText: "",
70
+ ttsText: "",
71
+ },
72
+ ],
73
+ needUploadResult: true,
74
+ noHalfPage: false,
75
+ pageControlRelated: false,
76
+ },
77
+ };
78
+ // Send command and wait for response (60 second timeout)
79
+ return new Promise((resolve, reject) => {
80
+ const timeout = setTimeout(() => {
81
+ wsManager.off("data-event", handler);
82
+ logger.error("超时: 拨打电话超时(60秒)", { toolCallId });
83
+ reject(new Error("拨打电话超时(60秒)"));
84
+ }, 60000);
85
+ // Listen for data events from WebSocket
86
+ const handler = (event) => {
87
+ if (event.intentName === "StartCall") {
120
88
  clearTimeout(timeout);
121
89
  wsManager.off("data-event", handler);
122
- reject(error);
123
- });
90
+ if (event.status === "success" && event.outputs) {
91
+ resolve({
92
+ content: [
93
+ {
94
+ type: "text",
95
+ text: JSON.stringify(event.outputs),
96
+ },
97
+ ],
98
+ });
99
+ }
100
+ else {
101
+ reject(new Error(`拨打电话失败: ${JSON.stringify(event.outputs)}`));
102
+ }
103
+ }
104
+ };
105
+ // Register event handler
106
+ wsManager.on("data-event", handler);
107
+ // Send the command
108
+ sendCommand({
109
+ config,
110
+ sessionId,
111
+ taskId,
112
+ messageId,
113
+ command,
114
+ toolCallId,
115
+ })
116
+ .then(() => {
117
+ })
118
+ .catch((error) => {
119
+ clearTimeout(timeout);
120
+ wsManager.off("data-event", handler);
121
+ reject(error);
124
122
  });
125
- },
126
- };
127
- }
123
+ });
124
+ },
125
+ };
@@ -1,6 +1,20 @@
1
- import type { SessionContext } from "./session-manager.js";
2
1
  /**
3
2
  * XY check plugin privilege tool - checks user authorization for device-side tools
4
3
  * used in scheduled tasks.
5
4
  */
6
- export declare function createCheckPluginPrivilegeTool(ctx: SessionContext): any;
5
+ export declare const checkPluginPrivilegeTool: {
6
+ name: string;
7
+ label: string;
8
+ description: string;
9
+ parameters: {
10
+ type: string;
11
+ properties: {
12
+ checkIntentName: {
13
+ type: string;
14
+ description: string;
15
+ };
16
+ };
17
+ required: string[];
18
+ };
19
+ execute(toolCallId: string, params: any): Promise<unknown>;
20
+ };