@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.
- package/dist/index.js +141 -1
- package/dist/src/acp-session-binding.d.ts +37 -0
- package/dist/src/acp-session-binding.js +237 -0
- package/dist/src/bot.js +62 -33
- package/dist/src/channel.js +68 -64
- package/dist/src/client.d.ts +5 -0
- package/dist/src/client.js +10 -0
- package/dist/src/cron-command.d.ts +2 -0
- package/dist/src/cron-command.js +14 -8
- package/dist/src/cron-query-handler.js +36 -0
- package/dist/src/cspl/call_api.js +4 -2
- package/dist/src/cspl/sentinel_hook.js +9 -8
- package/dist/src/cspl/upload_file.js +2 -2
- package/dist/src/formatter.js +72 -36
- package/dist/src/log-reporter/config-loader.d.ts +11 -0
- package/dist/src/log-reporter/config-loader.js +68 -0
- package/dist/src/log-reporter/cursor-store.d.ts +5 -0
- package/dist/src/log-reporter/cursor-store.js +26 -0
- package/dist/src/log-reporter/index.d.ts +10 -0
- package/dist/src/log-reporter/index.js +77 -0
- package/dist/src/log-reporter/reporter.d.ts +6 -0
- package/dist/src/log-reporter/reporter.js +17 -0
- package/dist/src/log-reporter/scanner.d.ts +6 -0
- package/dist/src/log-reporter/scanner.js +82 -0
- package/dist/src/log-reporter/types.d.ts +59 -0
- package/dist/src/log-reporter/types.js +2 -0
- package/dist/src/log-reporter/uploader.d.ts +6 -0
- package/dist/src/log-reporter/uploader.js +32 -0
- package/dist/src/memory-query-handler.d.ts +1 -0
- package/dist/src/memory-query-handler.js +283 -0
- package/dist/src/monitor.js +29 -9
- package/dist/src/outbound.js +5 -0
- package/dist/src/parser.d.ts +12 -0
- package/dist/src/parser.js +39 -13
- package/dist/src/provider.js +79 -16
- package/dist/src/reply-dispatcher.d.ts +3 -0
- package/dist/src/reply-dispatcher.js +166 -164
- package/dist/src/self-evolution-handler.js +2 -1
- package/dist/src/task-manager.d.ts +5 -6
- package/dist/src/task-manager.js +5 -9
- package/dist/src/tools/agent-as-skill-tool.d.ts +41 -2
- package/dist/src/tools/agent-as-skill-tool.js +144 -151
- package/dist/src/tools/calendar-tool.d.ts +24 -2
- package/dist/src/tools/calendar-tool.js +115 -117
- package/dist/src/tools/call-device-tool.d.ts +20 -6
- package/dist/src/tools/call-device-tool.js +116 -138
- package/dist/src/tools/call-phone-tool.d.ts +21 -2
- package/dist/src/tools/call-phone-tool.js +112 -114
- package/dist/src/tools/check-plugin-privilege-tool.d.ts +16 -2
- package/dist/src/tools/check-plugin-privilege-tool.js +141 -143
- package/dist/src/tools/create-alarm-tool.d.ts +39 -2
- package/dist/src/tools/create-alarm-tool.js +229 -231
- package/dist/src/tools/create-all-tools.js +8 -4
- package/dist/src/tools/delete-alarm-tool.d.ts +15 -2
- package/dist/src/tools/delete-alarm-tool.js +134 -136
- package/dist/src/tools/device-tool-map.d.ts +1 -1
- package/dist/src/tools/device-tool-map.js +9 -2
- package/dist/src/tools/discover-cross-devices-tool.d.ts +16 -2
- package/dist/src/tools/discover-cross-devices-tool.js +121 -124
- package/dist/src/tools/display-a2ui-card-bypath-tool.d.ts +21 -0
- package/dist/src/tools/display-a2ui-card-bypath-tool.js +65 -0
- package/dist/src/tools/get-alarm-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-alarm-tool-schema.js +10 -16
- package/dist/src/tools/get-calendar-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-calendar-tool-schema.js +8 -12
- package/dist/src/tools/get-collection-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-collection-tool-schema.js +9 -11
- package/dist/src/tools/get-contact-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-contact-tool-schema.js +10 -16
- package/dist/src/tools/get-device-file-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-device-file-tool-schema.js +9 -13
- package/dist/src/tools/get-email-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-email-tool-schema.js +8 -11
- package/dist/src/tools/get-note-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-note-tool-schema.js +9 -14
- package/dist/src/tools/get-photo-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-photo-tool-schema.js +9 -12
- package/dist/src/tools/image-reading-tool.d.ts +28 -2
- package/dist/src/tools/image-reading-tool.js +76 -76
- package/dist/src/tools/location-tool.d.ts +11 -2
- package/dist/src/tools/location-tool.js +93 -92
- package/dist/src/tools/login-token-tool.d.ts +20 -2
- package/dist/src/tools/login-token-tool.js +123 -125
- package/dist/src/tools/modify-alarm-tool.d.ts +47 -2
- package/dist/src/tools/modify-alarm-tool.js +250 -252
- package/dist/src/tools/modify-note-tool.d.ts +20 -2
- package/dist/src/tools/modify-note-tool.js +107 -109
- package/dist/src/tools/note-tool.d.ts +20 -2
- package/dist/src/tools/note-tool.js +106 -108
- package/dist/src/tools/query-app-message-tool.d.ts +28 -2
- package/dist/src/tools/query-app-message-tool.js +111 -113
- package/dist/src/tools/query-memory-data-tool.d.ts +28 -2
- package/dist/src/tools/query-memory-data-tool.js +112 -114
- package/dist/src/tools/query-todo-task-tool.d.ts +24 -2
- package/dist/src/tools/query-todo-task-tool.js +106 -108
- package/dist/src/tools/save-file-to-phone-tool.d.ts +24 -2
- package/dist/src/tools/save-file-to-phone-tool.js +130 -132
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +24 -2
- package/dist/src/tools/save-media-to-gallery-tool.js +137 -139
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +54 -2
- package/dist/src/tools/save-self-evolution-skill-tool.js +194 -194
- package/dist/src/tools/search-alarm-tool.d.ts +34 -2
- package/dist/src/tools/search-alarm-tool.js +174 -176
- package/dist/src/tools/search-calendar-tool.d.ts +24 -2
- package/dist/src/tools/search-calendar-tool.js +148 -150
- package/dist/src/tools/search-contact-tool.d.ts +16 -2
- package/dist/src/tools/search-contact-tool.js +101 -103
- package/dist/src/tools/search-email-tool.d.ts +21 -2
- package/dist/src/tools/search-email-tool.js +110 -112
- package/dist/src/tools/search-file-tool.d.ts +16 -2
- package/dist/src/tools/search-file-tool.js +104 -106
- package/dist/src/tools/search-message-tool.d.ts +16 -2
- package/dist/src/tools/search-message-tool.js +103 -105
- package/dist/src/tools/search-note-tool.d.ts +16 -2
- package/dist/src/tools/search-note-tool.js +98 -100
- package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -2
- package/dist/src/tools/search-photo-gallery-tool.js +35 -37
- package/dist/src/tools/send-cross-device-task-tool.d.ts +35 -2
- package/dist/src/tools/send-cross-device-task-tool.js +216 -150
- package/dist/src/tools/send-email-tool.d.ts +24 -2
- package/dist/src/tools/send-email-tool.js +108 -110
- package/dist/src/tools/send-file-to-user-tool.d.ts +20 -2
- package/dist/src/tools/send-file-to-user-tool.js +174 -178
- package/dist/src/tools/send-html-card-tool.d.ts +20 -2
- package/dist/src/tools/send-html-card-tool.js +85 -87
- package/dist/src/tools/send-message-tool.d.ts +20 -2
- package/dist/src/tools/send-message-tool.js +122 -124
- package/dist/src/tools/session-manager.d.ts +19 -52
- package/dist/src/tools/session-manager.js +95 -247
- package/dist/src/tools/upload-file-tool.d.ts +20 -2
- package/dist/src/tools/upload-file-tool.js +80 -82
- package/dist/src/tools/upload-photo-tool.d.ts +20 -2
- package/dist/src/tools/upload-photo-tool.js +68 -70
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +32 -2
- package/dist/src/tools/xiaoyi-add-collection-tool.js +146 -148
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +20 -2
- package/dist/src/tools/xiaoyi-collection-tool.js +114 -116
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +15 -2
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +127 -129
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +16 -2
- package/dist/src/tools/xiaoyi-gui-tool.js +92 -95
- package/dist/src/types.d.ts +6 -6
- package/dist/src/utils/config-manager.d.ts +3 -2
- package/dist/src/utils/config-manager.js +22 -2
- package/dist/src/utils/cron-push-map.d.ts +26 -0
- package/dist/src/utils/cron-push-map.js +131 -0
- package/dist/src/utils/logger.js +3 -14
- package/dist/src/websocket.d.ts +1 -1
- package/dist/src/websocket.js +29 -13
- package/package.json +1 -1
|
@@ -1,153 +1,131 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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:
|
|
122
|
+
text: `端工具参数错误:${error.message}。请确保arguments符合get_xxx_tool_schema返回的工具schema。`,
|
|
129
123
|
},
|
|
130
124
|
],
|
|
131
125
|
};
|
|
132
126
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
|
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 {
|
|
1
|
+
import { getCachedXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
-
import {
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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
|
|
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
|
+
};
|