@ynhcj/xiaoyi-channel 0.0.99-beta → 0.0.99-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.d.ts +4 -10
- package/dist/index.js +76 -66
- package/dist/provider-discovery.d.ts +2 -0
- package/dist/provider-discovery.js +4 -0
- package/dist/src/bot.js +29 -4
- package/dist/src/channel.js +2 -20
- package/dist/src/client.js +31 -22
- package/dist/src/cspl/call-api.js +6 -5
- package/dist/src/file-download.js +4 -3
- package/dist/src/file-upload.js +19 -18
- package/dist/src/formatter.d.ts +2 -0
- package/dist/src/formatter.js +9 -28
- package/dist/src/heartbeat.js +1 -1
- package/dist/src/message-queue.d.ts +17 -0
- package/dist/src/message-queue.js +51 -0
- package/dist/src/monitor.js +63 -14
- package/dist/src/outbound.js +19 -18
- package/dist/src/provider.d.ts +2 -1
- package/dist/src/provider.js +211 -41
- package/dist/src/push.js +16 -15
- package/dist/src/reply-dispatcher.js +12 -3
- package/dist/src/runtime.d.ts +3 -11
- package/dist/src/runtime.js +6 -18
- package/dist/src/self-evolution-handler.d.ts +6 -0
- package/dist/src/self-evolution-handler.js +100 -7
- package/dist/src/self-evolution-keyword.d.ts +9 -0
- package/dist/src/self-evolution-keyword.js +147 -0
- package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
- package/dist/src/self-evolution-tool-result-nudge.js +96 -0
- package/dist/src/skill-retriever/hooks.js +8 -12
- package/dist/src/skill-retriever/tool-search.js +22 -8
- package/dist/src/skill-retriever/types.d.ts +2 -0
- package/dist/src/steer-injector.js +1 -1
- package/dist/src/task-manager.d.ts +4 -0
- package/dist/src/task-manager.js +12 -1
- package/dist/src/tools/calendar-tool.d.ts +2 -1
- package/dist/src/tools/calendar-tool.js +112 -116
- package/dist/src/tools/call-device-tool.d.ts +2 -1
- package/dist/src/tools/call-device-tool.js +126 -103
- package/dist/src/tools/call-phone-tool.d.ts +2 -1
- package/dist/src/tools/call-phone-tool.js +109 -113
- package/dist/src/tools/create-alarm-tool.d.ts +2 -1
- package/dist/src/tools/create-alarm-tool.js +227 -231
- package/dist/src/tools/create-all-tools.d.ts +16 -0
- package/dist/src/tools/create-all-tools.js +50 -0
- package/dist/src/tools/delete-alarm-tool.d.ts +2 -1
- package/dist/src/tools/delete-alarm-tool.js +131 -135
- package/dist/src/tools/get-alarm-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-alarm-tool-schema.js +16 -10
- package/dist/src/tools/get-calendar-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-calendar-tool-schema.js +12 -8
- package/dist/src/tools/get-collection-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-collection-tool-schema.js +11 -9
- package/dist/src/tools/get-contact-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-contact-tool-schema.js +16 -10
- package/dist/src/tools/get-device-file-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-device-file-tool-schema.js +13 -9
- package/dist/src/tools/get-email-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-email-tool-schema.js +11 -8
- package/dist/src/tools/get-note-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-note-tool-schema.js +14 -9
- package/dist/src/tools/get-photo-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-photo-tool-schema.js +12 -9
- package/dist/src/tools/image-reading-tool.d.ts +2 -1
- package/dist/src/tools/image-reading-tool.js +86 -90
- package/dist/src/tools/location-tool.d.ts +2 -1
- package/dist/src/tools/location-tool.js +87 -91
- package/dist/src/tools/login-token-tool.d.ts +3 -2
- package/dist/src/tools/login-token-tool.js +114 -117
- package/dist/src/tools/modify-alarm-tool.d.ts +2 -1
- package/dist/src/tools/modify-alarm-tool.js +232 -236
- package/dist/src/tools/modify-note-tool.d.ts +2 -1
- package/dist/src/tools/modify-note-tool.js +104 -108
- package/dist/src/tools/note-tool.d.ts +2 -1
- package/dist/src/tools/note-tool.js +103 -107
- package/dist/src/tools/query-app-message-tool.d.ts +2 -1
- package/dist/src/tools/query-app-message-tool.js +108 -111
- package/dist/src/tools/query-memory-data-tool.d.ts +2 -1
- package/dist/src/tools/query-memory-data-tool.js +109 -112
- package/dist/src/tools/query-todo-task-tool.d.ts +2 -1
- package/dist/src/tools/query-todo-task-tool.js +103 -106
- package/dist/src/tools/save-file-to-phone-tool.d.ts +2 -1
- package/dist/src/tools/save-file-to-phone-tool.js +127 -131
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
- package/dist/src/tools/save-media-to-gallery-tool.js +134 -138
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +2 -0
- package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
- package/dist/src/tools/search-alarm-tool.d.ts +2 -1
- package/dist/src/tools/search-alarm-tool.js +171 -175
- package/dist/src/tools/search-calendar-tool.d.ts +2 -1
- package/dist/src/tools/search-calendar-tool.js +145 -149
- package/dist/src/tools/search-contact-tool.d.ts +2 -1
- package/dist/src/tools/search-contact-tool.js +98 -102
- package/dist/src/tools/search-email-tool.d.ts +2 -1
- package/dist/src/tools/search-email-tool.js +107 -111
- package/dist/src/tools/search-file-tool.d.ts +2 -1
- package/dist/src/tools/search-file-tool.js +99 -103
- package/dist/src/tools/search-message-tool.d.ts +2 -1
- package/dist/src/tools/search-message-tool.js +100 -104
- package/dist/src/tools/search-note-tool.d.ts +2 -1
- package/dist/src/tools/search-note-tool.js +95 -99
- package/dist/src/tools/search-photo-gallery-tool.d.ts +2 -1
- package/dist/src/tools/search-photo-gallery-tool.js +34 -38
- package/dist/src/tools/send-email-tool.d.ts +2 -1
- package/dist/src/tools/send-email-tool.js +105 -108
- package/dist/src/tools/send-file-to-user-tool.d.ts +2 -1
- package/dist/src/tools/send-file-to-user-tool.js +154 -155
- package/dist/src/tools/send-message-tool.d.ts +2 -1
- package/dist/src/tools/send-message-tool.js +119 -123
- package/dist/src/tools/session-manager.d.ts +21 -6
- package/dist/src/tools/session-manager.js +147 -18
- package/dist/src/tools/upload-file-tool.d.ts +2 -1
- package/dist/src/tools/upload-file-tool.js +78 -82
- package/dist/src/tools/upload-photo-tool.d.ts +2 -1
- package/dist/src/tools/upload-photo-tool.js +69 -73
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-add-collection-tool.js +143 -147
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-collection-tool.js +111 -115
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +124 -128
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-gui-tool.js +84 -88
- package/dist/src/utils/logger.js +20 -18
- package/dist/src/utils/runtime-manager.js +24 -2
- package/dist/src/utils/self-evolution-manager.d.ts +10 -0
- package/dist/src/utils/self-evolution-manager.js +69 -0
- package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
- package/dist/src/utils/tool-call-nudge-manager.js +47 -0
- package/dist/src/websocket.d.ts +3 -0
- package/dist/src/websocket.js +81 -28
- package/openclaw.plugin.json +22 -0
- package/package.json +3 -3
|
@@ -1,134 +1,130 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
-
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
3
|
/**
|
|
5
4
|
* XY calendar event tool - creates a calendar event on user's device.
|
|
6
5
|
* Requires title, dtStart (start time), and dtEnd (end time) parameters.
|
|
7
6
|
* Time format must be: yyyy-mm-dd hh:mm:ss
|
|
8
7
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export function createCalendarTool(ctx) {
|
|
9
|
+
const { config, sessionId, taskId, messageId } = ctx;
|
|
10
|
+
return {
|
|
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秒),请勿重复调用,超时或失败时最多重试一次。
|
|
13
14
|
注意事项:使用该工具之前需获取当前真实时间
|
|
14
15
|
|
|
15
16
|
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
16
17
|
`,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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)",
|
|
32
|
+
},
|
|
31
33
|
},
|
|
34
|
+
required: ["title", "dtStart", "dtEnd"],
|
|
32
35
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
52
|
-
// Get WebSocket manager
|
|
53
|
-
const wsManager = getXYWebSocketManager(config);
|
|
54
|
-
// Build CreateCalendarEvent command
|
|
55
|
-
const command = {
|
|
56
|
-
header: {
|
|
57
|
-
namespace: "Common",
|
|
58
|
-
name: "ActionAndResult",
|
|
59
|
-
},
|
|
60
|
-
payload: {
|
|
61
|
-
cardParam: {},
|
|
62
|
-
executeParam: {
|
|
63
|
-
executeMode: "background",
|
|
64
|
-
intentName: "CreateCalendarEvent",
|
|
65
|
-
bundleName: "com.huawei.hmos.calendardata",
|
|
66
|
-
dimension: "",
|
|
67
|
-
needUnlock: true,
|
|
68
|
-
actionResponse: true,
|
|
69
|
-
timeOut: 5,
|
|
70
|
-
intentParam: {
|
|
71
|
-
title: params.title,
|
|
72
|
-
dtStart: dtStartMs,
|
|
73
|
-
dtEnd: dtEndMs,
|
|
74
|
-
},
|
|
75
|
-
achieveType: "INTENT",
|
|
36
|
+
async execute(toolCallId, params) {
|
|
37
|
+
// Validate parameters
|
|
38
|
+
if (!params.title || !params.dtStart || !params.dtEnd) {
|
|
39
|
+
throw new Error("Missing required parameters: title, dtStart, and dtEnd are required");
|
|
40
|
+
}
|
|
41
|
+
// Convert time strings to millisecond timestamps
|
|
42
|
+
const dtStartMs = new Date(params.dtStart).getTime();
|
|
43
|
+
const dtEndMs = new Date(params.dtEnd).getTime();
|
|
44
|
+
if (isNaN(dtStartMs) || isNaN(dtEndMs)) {
|
|
45
|
+
throw new Error("Invalid time format. Required format: yyyy-mm-dd hh:mm:ss (e.g., 2024-01-15 14:30:00)");
|
|
46
|
+
}
|
|
47
|
+
// Get WebSocket manager
|
|
48
|
+
const wsManager = getXYWebSocketManager(config);
|
|
49
|
+
// Build CreateCalendarEvent command
|
|
50
|
+
const command = {
|
|
51
|
+
header: {
|
|
52
|
+
namespace: "Common",
|
|
53
|
+
name: "ActionAndResult",
|
|
76
54
|
},
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
55
|
+
payload: {
|
|
56
|
+
cardParam: {},
|
|
57
|
+
executeParam: {
|
|
58
|
+
executeMode: "background",
|
|
59
|
+
intentName: "CreateCalendarEvent",
|
|
60
|
+
bundleName: "com.huawei.hmos.calendardata",
|
|
61
|
+
dimension: "",
|
|
62
|
+
needUnlock: true,
|
|
63
|
+
actionResponse: true,
|
|
64
|
+
timeOut: 5,
|
|
65
|
+
intentParam: {
|
|
66
|
+
title: params.title,
|
|
67
|
+
dtStart: dtStartMs,
|
|
68
|
+
dtEnd: dtEndMs,
|
|
69
|
+
},
|
|
70
|
+
achieveType: "INTENT",
|
|
82
71
|
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
clearTimeout(timeout);
|
|
72
|
+
responses: [
|
|
73
|
+
{
|
|
74
|
+
resultCode: "",
|
|
75
|
+
displayText: "",
|
|
76
|
+
ttsText: "",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
needUploadResult: true,
|
|
80
|
+
noHalfPage: false,
|
|
81
|
+
pageControlRelated: false,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
// Send command and wait for response (60 second timeout)
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const timeout = setTimeout(() => {
|
|
99
87
|
wsManager.off("data-event", handler);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
88
|
+
reject(new Error("创建日程超时(60秒)"));
|
|
89
|
+
}, 60000);
|
|
90
|
+
// Listen for data events from WebSocket
|
|
91
|
+
const handler = (event) => {
|
|
92
|
+
if (event.intentName === "CreateCalendarEvent") {
|
|
93
|
+
clearTimeout(timeout);
|
|
94
|
+
wsManager.off("data-event", handler);
|
|
95
|
+
if (event.status === "success" && event.outputs) {
|
|
96
|
+
resolve({
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
type: "text",
|
|
100
|
+
text: JSON.stringify(event.outputs),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
reject(new Error(`创建日程失败: ${event.status}`));
|
|
107
|
+
}
|
|
112
108
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
109
|
+
};
|
|
110
|
+
// Register event handler
|
|
111
|
+
wsManager.on("data-event", handler);
|
|
112
|
+
// Send the command
|
|
113
|
+
sendCommand({
|
|
114
|
+
config,
|
|
115
|
+
sessionId,
|
|
116
|
+
taskId,
|
|
117
|
+
messageId,
|
|
118
|
+
command,
|
|
119
|
+
})
|
|
120
|
+
.then(() => {
|
|
121
|
+
})
|
|
122
|
+
.catch((error) => {
|
|
123
|
+
clearTimeout(timeout);
|
|
124
|
+
wsManager.off("data-event", handler);
|
|
125
|
+
reject(error);
|
|
126
|
+
});
|
|
131
127
|
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { SessionContext } from "./session-manager.js";
|
|
1
2
|
/**
|
|
2
3
|
* call_device_tool - 通用端工具调度器。
|
|
3
4
|
* LLM 必须先通过 get_xxx_tool_schema 获取具体工具 schema,再用本工具执行。
|
|
4
5
|
*/
|
|
5
|
-
export declare
|
|
6
|
+
export declare function createCallDeviceTool(ctx: SessionContext): any;
|
|
@@ -1,92 +1,115 @@
|
|
|
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 { 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";
|
|
25
25
|
import { sendStatusUpdate } from "../formatter.js";
|
|
26
|
-
import { getCurrentSessionContext } from "./session-manager.js";
|
|
27
26
|
import { getCurrentTaskId, getCurrentMessageId } from "../task-manager.js";
|
|
28
|
-
/**
|
|
29
|
-
* 端工具注册表 —— 按 name 索引所有可通过 call_device_tool 调度的工具。
|
|
30
|
-
*/
|
|
31
|
-
const deviceToolRegistry = new Map([
|
|
32
|
-
[noteTool.name, noteTool],
|
|
33
|
-
[searchNoteTool.name, searchNoteTool],
|
|
34
|
-
[modifyNoteTool.name, modifyNoteTool],
|
|
35
|
-
[createAlarmTool.name, createAlarmTool],
|
|
36
|
-
[searchAlarmTool.name, searchAlarmTool],
|
|
37
|
-
[modifyAlarmTool.name, modifyAlarmTool],
|
|
38
|
-
[deleteAlarmTool.name, deleteAlarmTool],
|
|
39
|
-
[searchContactTool.name, searchContactTool],
|
|
40
|
-
[callPhoneTool.name, callPhoneTool],
|
|
41
|
-
[searchMessageTool.name, searchMessageTool],
|
|
42
|
-
[sendMessageTool.name, sendMessageTool],
|
|
43
|
-
[xiaoyiAddCollectionTool.name, xiaoyiAddCollectionTool],
|
|
44
|
-
[xiaoyiCollectionTool.name, xiaoyiCollectionTool],
|
|
45
|
-
[xiaoyiDeleteCollectionTool.name, xiaoyiDeleteCollectionTool],
|
|
46
|
-
[calendarTool.name, calendarTool],
|
|
47
|
-
[searchCalendarTool.name, searchCalendarTool],
|
|
48
|
-
[searchPhotoGalleryTool.name, searchPhotoGalleryTool],
|
|
49
|
-
[uploadPhotoTool.name, uploadPhotoTool],
|
|
50
|
-
[saveMediaToGalleryTool.name, saveMediaToGalleryTool],
|
|
51
|
-
[searchFileTool.name, searchFileTool],
|
|
52
|
-
[uploadFileTool.name, uploadFileTool],
|
|
53
|
-
[saveFileToPhoneTool.name, saveFileToPhoneTool],
|
|
54
|
-
[sendEmailTool.name, sendEmailTool],
|
|
55
|
-
[searchEmailTool.name, searchEmailTool],
|
|
56
|
-
]);
|
|
57
27
|
/**
|
|
58
28
|
* call_device_tool - 通用端工具调度器。
|
|
59
29
|
* LLM 必须先通过 get_xxx_tool_schema 获取具体工具 schema,再用本工具执行。
|
|
60
30
|
*/
|
|
61
|
-
export
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
},
|
|
75
101
|
},
|
|
102
|
+
required: ["toolName", "arguments"],
|
|
76
103
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const ctx = getCurrentSessionContext();
|
|
83
|
-
if (ctx) {
|
|
84
|
-
const currentTaskId = getCurrentTaskId(ctx.sessionId) ?? ctx.taskId;
|
|
85
|
-
const currentMessageId = getCurrentMessageId(ctx.sessionId) ?? ctx.messageId;
|
|
104
|
+
async execute(toolCallId, params) {
|
|
105
|
+
const { toolName, arguments: toolArgs } = params;
|
|
106
|
+
// 向用户端发送具体工具名的状态更新
|
|
107
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
108
|
+
const currentMessageId = getCurrentMessageId(sessionId) ?? messageId;
|
|
86
109
|
try {
|
|
87
110
|
await sendStatusUpdate({
|
|
88
|
-
config
|
|
89
|
-
sessionId
|
|
111
|
+
config,
|
|
112
|
+
sessionId,
|
|
90
113
|
taskId: currentTaskId,
|
|
91
114
|
messageId: currentMessageId,
|
|
92
115
|
text: `正在使用工具: ${toolName}...`,
|
|
@@ -96,35 +119,35 @@ export const callDeviceTool = {
|
|
|
96
119
|
catch (_) {
|
|
97
120
|
// 状态更新失败不影响工具执行
|
|
98
121
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!tool) {
|
|
102
|
-
return {
|
|
103
|
-
content: [
|
|
104
|
-
{
|
|
105
|
-
type: "text",
|
|
106
|
-
text: `端工具${toolName}不存在。请确保toolName为get_xxx_tool_schema返回的工具的name。`,
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
return await tool.execute(toolCallId, toolArgs);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
// ToolInputError (.name === "ToolInputError") 或其他参数校验错误
|
|
116
|
-
if (error.name === "ToolInputError") {
|
|
122
|
+
const tool = deviceToolRegistry.get(toolName);
|
|
123
|
+
if (!tool) {
|
|
117
124
|
return {
|
|
118
125
|
content: [
|
|
119
126
|
{
|
|
120
127
|
type: "text",
|
|
121
|
-
text:
|
|
128
|
+
text: `端工具${toolName}不存在。请确保toolName为get_xxx_tool_schema返回的工具的name。`,
|
|
122
129
|
},
|
|
123
130
|
],
|
|
124
131
|
};
|
|
125
132
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { SessionContext } from "./session-manager.js";
|
|
1
2
|
/**
|
|
2
3
|
* XY call phone tool - makes a phone call on user's device.
|
|
3
4
|
* Requires phoneNumber parameter and optional slotId (0 for primary SIM, 1 for secondary SIM).
|
|
4
5
|
*/
|
|
5
|
-
export declare
|
|
6
|
+
export declare function createCallPhoneTool(ctx: SessionContext): any;
|