@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,6 +1,6 @@
|
|
|
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 upload photo tool - uploads local photos to get publicly accessible URLs.
|
|
@@ -10,12 +10,10 @@ import { logger } from "../utils/logger.js";
|
|
|
10
10
|
* 1. Call search_photo_gallery tool first to get mediaUris of photos
|
|
11
11
|
* 2. Use the mediaUris (maximum 5 at a time) to get public URLs
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
label: "Upload Photo",
|
|
18
|
-
description: `工具能力描述:将用户本地设备文件回传并获取可公网访问的 URL。
|
|
13
|
+
export const uploadPhotoTool = {
|
|
14
|
+
name: "upload_photo",
|
|
15
|
+
label: "Upload Photo",
|
|
16
|
+
description: `工具能力描述:将用户本地设备文件回传并获取可公网访问的 URL。
|
|
19
17
|
|
|
20
18
|
前置工具调用:此工具使用前必须先通过call_device_tool工具调用 search_photo_gallery 工具获取照片的 mediaUri或者thumbnailUri
|
|
21
19
|
工具参数说明:
|
|
@@ -26,74 +24,74 @@ export function createUploadPhotoTool(ctx) {
|
|
|
26
24
|
注意事项:
|
|
27
25
|
a. 操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
28
26
|
b. 此工具返回的图片链接为用户公网可访问的链接,如果需要后续操作需要下载到本地,如果需要返回给用户查看则直接以图片markdown的形式返回给用户`,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
27
|
+
parameters: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
mediaUris: {
|
|
31
|
+
// 不指定 type,允许传入数组或 JSON 字符串
|
|
32
|
+
// 具体的类型验证和转换在 execute 函数内部进行
|
|
33
|
+
description: "照片在手机本地的 URI 数组,必须先通过 search_photo_gallery 工具获取。每次最多支持 3 条 URI。",
|
|
37
34
|
},
|
|
38
|
-
required: ["mediaUris"],
|
|
39
35
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
36
|
+
required: ["mediaUris"],
|
|
37
|
+
},
|
|
38
|
+
async execute(toolCallId, params) {
|
|
39
|
+
const _c = getCurrentSessionContext();
|
|
40
|
+
const { config, sessionId, taskId, messageId } = _c;
|
|
41
|
+
// ===== 参数规范化:兼容数组和 JSON 字符串 =====
|
|
42
|
+
let mediaUris = null;
|
|
43
|
+
if (!params.mediaUris) {
|
|
44
|
+
throw new Error("Missing required parameter: mediaUris");
|
|
45
|
+
}
|
|
46
|
+
// 情况1: 已经是数组
|
|
47
|
+
if (Array.isArray(params.mediaUris)) {
|
|
48
|
+
mediaUris = params.mediaUris;
|
|
49
|
+
}
|
|
50
|
+
// 情况2: 是字符串,尝试解析为 JSON 数组
|
|
51
|
+
else if (typeof params.mediaUris === 'string') {
|
|
52
|
+
try {
|
|
53
|
+
const parsed = JSON.parse(params.mediaUris);
|
|
54
|
+
if (Array.isArray(parsed)) {
|
|
55
|
+
mediaUris = parsed;
|
|
60
56
|
}
|
|
61
|
-
|
|
62
|
-
throw new Error(
|
|
57
|
+
else {
|
|
58
|
+
throw new Error("mediaUris must be an array or a JSON string representing an array");
|
|
63
59
|
}
|
|
64
60
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
throw new Error(`mediaUris must be an array or a JSON string, got ${typeof params.mediaUris}`);
|
|
61
|
+
catch (parseError) {
|
|
62
|
+
throw new Error(`mediaUris must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
68
63
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
64
|
+
}
|
|
65
|
+
// 情况3: 其他类型,报错
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(`mediaUris must be an array or a JSON string, got ${typeof params.mediaUris}`);
|
|
68
|
+
}
|
|
69
|
+
// 验证数组非空
|
|
70
|
+
if (!mediaUris || mediaUris.length === 0) {
|
|
71
|
+
throw new Error("mediaUris array cannot be empty");
|
|
72
|
+
}
|
|
73
|
+
// Validate maximum 5 URIs
|
|
74
|
+
if (mediaUris.length > 5) {
|
|
75
|
+
throw new Error(`最多支持 5 条 mediaUri,当前提供了 ${mediaUris.length} 条。请分批处理。`);
|
|
76
|
+
}
|
|
77
|
+
// Get WebSocket manager
|
|
78
|
+
const wsManager = getCachedXYWebSocketManager();
|
|
79
|
+
// Get public URLs for the photos
|
|
80
|
+
const imageUrls = await getPhotoUrls(wsManager, config, sessionId, taskId, messageId, toolCallId, mediaUris);
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: JSON.stringify({
|
|
86
|
+
imageUrls,
|
|
87
|
+
count: imageUrls.length,
|
|
88
|
+
message: `成功获取 ${imageUrls.length} 张照片的公网访问 URL`
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
97
95
|
/**
|
|
98
96
|
* Get public URLs for photos using mediaUris
|
|
99
97
|
* Returns array of publicly accessible image URLs
|
|
@@ -1,5 +1,35 @@
|
|
|
1
|
-
import type { SessionContext } from "./session-manager.js";
|
|
2
1
|
/**
|
|
3
2
|
* XY add collection tool - adds data to user's XiaoYi collection.
|
|
4
3
|
*/
|
|
5
|
-
export declare
|
|
4
|
+
export declare const xiaoyiAddCollectionTool: {
|
|
5
|
+
name: string;
|
|
6
|
+
label: string;
|
|
7
|
+
description: string;
|
|
8
|
+
parameters: {
|
|
9
|
+
type: string;
|
|
10
|
+
properties: {
|
|
11
|
+
content: {
|
|
12
|
+
type: string;
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
uri: {
|
|
16
|
+
type: string;
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
sourceAppBundleName: {
|
|
20
|
+
type: string;
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
dataType: {
|
|
24
|
+
type: string;
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
title: {
|
|
28
|
+
type: string;
|
|
29
|
+
description: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
required: string[];
|
|
33
|
+
};
|
|
34
|
+
execute(toolCallId: string, params: any): Promise<unknown>;
|
|
35
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
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
|
import { XYFileUploadService } from "../file-upload.js";
|
|
6
6
|
/**
|
|
@@ -18,12 +18,10 @@ class ToolInputError extends Error {
|
|
|
18
18
|
/**
|
|
19
19
|
* XY add collection tool - adds data to user's XiaoYi collection.
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
label: "Add XiaoYi Collection",
|
|
26
|
-
description: `向小艺收藏(也叫小艺帮记)中添加公共知识数据,可以给用户提供个性化体验。任何用户希望保存到个人化知识库中的数据都可以调用本技能。不同类型的数据对应的数据要求如下:
|
|
21
|
+
export const xiaoyiAddCollectionTool = {
|
|
22
|
+
name: "add_collection",
|
|
23
|
+
label: "Add XiaoYi Collection",
|
|
24
|
+
description: `向小艺收藏(也叫小艺帮记)中添加公共知识数据,可以给用户提供个性化体验。任何用户希望保存到个人化知识库中的数据都可以调用本技能。不同类型的数据对应的数据要求如下:
|
|
27
25
|
请求入参说明:
|
|
28
26
|
● content:必填字段,数据类型为string,功能描述是该字段是用户添加收藏的链接url或文本原文。适用于HYPER_LINK和TEXT类型。
|
|
29
27
|
● uri:必填字段,数据类型为string,功能描述是该字段是图片或文件的端存储地址链接。适用于IMAGE和FILE类型。
|
|
@@ -40,155 +38,155 @@ export function createXiaoyiAddCollectionTool(ctx) {
|
|
|
40
38
|
|
|
41
39
|
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
42
40
|
`,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
parameters: {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
content: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "必填字段(HYPER_LINK/TEXT类型时)。用户添加收藏的链接url或文本原文。",
|
|
47
|
+
},
|
|
48
|
+
uri: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: `必填字段(IMAGE/FILE类型时)。图片或文件的地址链接。
|
|
53
51
|
uri具备三种严格的格式
|
|
54
52
|
(1) http或者https开头的公网链接,一般是用户通过联网搜索获取的文件地址,不允许自行编造,此类链接填入时必须确保真实
|
|
55
53
|
(2) file://开头的链接,此类链接必须来源于query_collection结果或者search_file或者search_photo_gallery的结果,不允许自行编造
|
|
56
54
|
(3) 本地路径例,如/tmp/xy_channel/xxx,此类路径是文件保存在当前openclaw运行环境的本地目录,可以直接填入,不要擅自拼接http://或者file://前缀`,
|
|
57
|
-
},
|
|
58
|
-
sourceAppBundleName: {
|
|
59
|
-
type: "string",
|
|
60
|
-
description: "非必填字段。标识该数据的来源应用。",
|
|
61
|
-
},
|
|
62
|
-
dataType: {
|
|
63
|
-
type: "string",
|
|
64
|
-
description: "必填字段。标识数据类型:HYPER_LINK表示网页,TEXT表示文本,IMAGE表示图片,FILE表示文件。",
|
|
65
|
-
},
|
|
66
|
-
title: {
|
|
67
|
-
type: "string",
|
|
68
|
-
description: "非必填字段。标识文件类型数据的文件名称。适用于FILE类型。",
|
|
69
|
-
},
|
|
70
55
|
},
|
|
71
|
-
|
|
56
|
+
sourceAppBundleName: {
|
|
57
|
+
type: "string",
|
|
58
|
+
description: "非必填字段。标识该数据的来源应用。",
|
|
59
|
+
},
|
|
60
|
+
dataType: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "必填字段。标识数据类型:HYPER_LINK表示网页,TEXT表示文本,IMAGE表示图片,FILE表示文件。",
|
|
63
|
+
},
|
|
64
|
+
title: {
|
|
65
|
+
type: "string",
|
|
66
|
+
description: "非必填字段。标识文件类型数据的文件名称。适用于FILE类型。",
|
|
67
|
+
},
|
|
72
68
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
dataType,
|
|
100
|
-
};
|
|
101
|
-
if (content) {
|
|
102
|
-
intentParam.content = content;
|
|
69
|
+
required: ["dataType"],
|
|
70
|
+
},
|
|
71
|
+
async execute(toolCallId, params) {
|
|
72
|
+
const _c = getCurrentSessionContext();
|
|
73
|
+
const { config, sessionId, taskId, messageId } = _c;
|
|
74
|
+
// Validate parameters
|
|
75
|
+
const { content, uri, sourceAppBundleName, dataType, title } = params;
|
|
76
|
+
const validTypes = ["HYPER_LINK", "TEXT", "IMAGE", "FILE"];
|
|
77
|
+
if (!dataType || !validTypes.includes(dataType)) {
|
|
78
|
+
throw new ToolInputError(`dataType必填且必须为 HYPER_LINK、TEXT、IMAGE、FILE 之一,当前值: ${dataType}`);
|
|
79
|
+
}
|
|
80
|
+
if ((dataType === "HYPER_LINK" || dataType === "TEXT") && (!content || typeof content !== "string")) {
|
|
81
|
+
throw new ToolInputError(`dataType为${dataType}时,content字段必填且不能为空`);
|
|
82
|
+
}
|
|
83
|
+
if ((dataType === "IMAGE" || dataType === "FILE") && (!uri || typeof uri !== "string")) {
|
|
84
|
+
throw new ToolInputError(`dataType为${dataType}时,uri字段必填且不能为空`);
|
|
85
|
+
}
|
|
86
|
+
// Get WebSocket manager
|
|
87
|
+
const wsManager = getCachedXYWebSocketManager();
|
|
88
|
+
// Handle uri: upload local paths to get public URL
|
|
89
|
+
let publicUri = uri;
|
|
90
|
+
if (uri && !uri.startsWith("http://") && !uri.startsWith("https://") && !uri.startsWith("file://")) {
|
|
91
|
+
const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
|
|
92
|
+
publicUri = await uploadService.uploadFileAndGetUrl(uri);
|
|
93
|
+
if (!publicUri) {
|
|
94
|
+
throw new Error("本地文件上传失败,无法获取公网URL");
|
|
103
95
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
96
|
+
}
|
|
97
|
+
// Build intentParam
|
|
98
|
+
const intentParam = {
|
|
99
|
+
dataType,
|
|
100
|
+
};
|
|
101
|
+
if (content) {
|
|
102
|
+
intentParam.content = content;
|
|
103
|
+
}
|
|
104
|
+
if (publicUri) {
|
|
105
|
+
intentParam.uri = publicUri;
|
|
106
|
+
}
|
|
107
|
+
if (sourceAppBundleName) {
|
|
108
|
+
intentParam.sourceAppBundleName = sourceAppBundleName;
|
|
109
|
+
}
|
|
110
|
+
if (title) {
|
|
111
|
+
intentParam.title = title;
|
|
112
|
+
}
|
|
113
|
+
// Build AddCollection command
|
|
114
|
+
const command = {
|
|
115
|
+
header: {
|
|
116
|
+
namespace: "Common",
|
|
117
|
+
name: "Action",
|
|
118
|
+
},
|
|
119
|
+
payload: {
|
|
120
|
+
cardParam: {},
|
|
121
|
+
executeParam: {
|
|
122
|
+
executeMode: "background",
|
|
123
|
+
intentName: "AddCollection",
|
|
124
|
+
bundleName: "com.huawei.hmos.vassistant",
|
|
125
|
+
needUnlock: true,
|
|
126
|
+
actionResponse: true,
|
|
127
|
+
appType: "OHOS_APP",
|
|
128
|
+
timeOut: 5,
|
|
129
|
+
intentParam,
|
|
130
|
+
permissionId: [],
|
|
131
|
+
achieveType: "INTENT",
|
|
118
132
|
},
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
bundleName: "com.huawei.hmos.vassistant",
|
|
125
|
-
needUnlock: true,
|
|
126
|
-
actionResponse: true,
|
|
127
|
-
appType: "OHOS_APP",
|
|
128
|
-
timeOut: 5,
|
|
129
|
-
intentParam,
|
|
130
|
-
permissionId: [],
|
|
131
|
-
achieveType: "INTENT",
|
|
133
|
+
responses: [
|
|
134
|
+
{
|
|
135
|
+
resultCode: "",
|
|
136
|
+
displayText: "",
|
|
137
|
+
ttsText: "",
|
|
132
138
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
logger.error("超时: 添加小艺收藏超时(60秒)", { toolCallId });
|
|
150
|
-
reject(new Error("添加小艺收藏超时(60秒)"));
|
|
151
|
-
}, 60000);
|
|
152
|
-
// Listen for data events from WebSocket
|
|
153
|
-
const handler = (event) => {
|
|
154
|
-
if (event.intentName === "AddCollection") {
|
|
155
|
-
clearTimeout(timeout);
|
|
156
|
-
wsManager.off("data-event", handler);
|
|
157
|
-
if (event.status === "success" && event.outputs) {
|
|
158
|
-
resolve({
|
|
159
|
-
content: [
|
|
160
|
-
{
|
|
161
|
-
type: "text",
|
|
162
|
-
text: JSON.stringify(event.outputs),
|
|
163
|
-
}
|
|
164
|
-
]
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
reject(new Error(`添加小艺收藏失败: ${JSON.stringify(event.outputs)}`));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
// Register event handler
|
|
173
|
-
wsManager.on("data-event", handler);
|
|
174
|
-
// Send the command
|
|
175
|
-
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
176
|
-
sendCommand({
|
|
177
|
-
config,
|
|
178
|
-
sessionId,
|
|
179
|
-
taskId: currentTaskId,
|
|
180
|
-
messageId,
|
|
181
|
-
command,
|
|
182
|
-
toolCallId,
|
|
183
|
-
})
|
|
184
|
-
.then(() => {
|
|
185
|
-
})
|
|
186
|
-
.catch((error) => {
|
|
139
|
+
],
|
|
140
|
+
needUploadResult: true,
|
|
141
|
+
noHalfPage: false,
|
|
142
|
+
pageControlRelated: false,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
// Send command and wait for response (60 second timeout)
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
const timeout = setTimeout(() => {
|
|
148
|
+
wsManager.off("data-event", handler);
|
|
149
|
+
logger.error("超时: 添加小艺收藏超时(60秒)", { toolCallId });
|
|
150
|
+
reject(new Error("添加小艺收藏超时(60秒)"));
|
|
151
|
+
}, 60000);
|
|
152
|
+
// Listen for data events from WebSocket
|
|
153
|
+
const handler = (event) => {
|
|
154
|
+
if (event.intentName === "AddCollection") {
|
|
187
155
|
clearTimeout(timeout);
|
|
188
156
|
wsManager.off("data-event", handler);
|
|
189
|
-
|
|
190
|
-
|
|
157
|
+
if (event.status === "success" && event.outputs) {
|
|
158
|
+
resolve({
|
|
159
|
+
content: [
|
|
160
|
+
{
|
|
161
|
+
type: "text",
|
|
162
|
+
text: JSON.stringify(event.outputs),
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
reject(new Error(`添加小艺收藏失败: ${JSON.stringify(event.outputs)}`));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
// Register event handler
|
|
173
|
+
wsManager.on("data-event", handler);
|
|
174
|
+
// Send the command
|
|
175
|
+
sendCommand({
|
|
176
|
+
config,
|
|
177
|
+
sessionId,
|
|
178
|
+
taskId,
|
|
179
|
+
messageId,
|
|
180
|
+
command,
|
|
181
|
+
toolCallId,
|
|
182
|
+
})
|
|
183
|
+
.then(() => {
|
|
184
|
+
})
|
|
185
|
+
.catch((error) => {
|
|
186
|
+
clearTimeout(timeout);
|
|
187
|
+
wsManager.off("data-event", handler);
|
|
188
|
+
reject(error);
|
|
191
189
|
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
};
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
import type { SessionContext } from "./session-manager.js";
|
|
2
1
|
/**
|
|
3
2
|
* XY collection tool - retrieves user's collection data from XiaoYi.
|
|
4
3
|
* Returns personalized knowledge data saved in user's collection.
|
|
5
4
|
*/
|
|
6
|
-
export declare
|
|
5
|
+
export declare const xiaoyiCollectionTool: {
|
|
6
|
+
name: string;
|
|
7
|
+
label: string;
|
|
8
|
+
description: string;
|
|
9
|
+
parameters: {
|
|
10
|
+
type: string;
|
|
11
|
+
properties: {
|
|
12
|
+
queryAll: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
query: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
required: any[];
|
|
22
|
+
};
|
|
23
|
+
execute(toolCallId: string, params: any): Promise<unknown>;
|
|
24
|
+
};
|