@ynhcj/xiaoyi-channel 0.0.97-beta → 0.0.97-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 (140) hide show
  1. package/dist/index.d.ts +6 -9
  2. package/dist/index.js +26 -21
  3. package/dist/provider-discovery.d.ts +2 -0
  4. package/dist/provider-discovery.js +4 -0
  5. package/dist/src/bot.js +29 -4
  6. package/dist/src/channel.js +2 -19
  7. package/dist/src/client.js +31 -22
  8. package/dist/src/cspl/call-api.js +6 -5
  9. package/dist/src/file-download.js +4 -3
  10. package/dist/src/file-upload.js +19 -18
  11. package/dist/src/formatter.d.ts +2 -0
  12. package/dist/src/formatter.js +9 -28
  13. package/dist/src/heartbeat.js +1 -1
  14. package/dist/src/login-token-handler.d.ts +8 -0
  15. package/dist/src/login-token-handler.js +60 -0
  16. package/dist/src/message-queue.d.ts +17 -0
  17. package/dist/src/message-queue.js +51 -0
  18. package/dist/src/monitor.js +70 -14
  19. package/dist/src/outbound.js +19 -18
  20. package/dist/src/provider.d.ts +2 -1
  21. package/dist/src/provider.js +245 -38
  22. package/dist/src/push.js +16 -15
  23. package/dist/src/reply-dispatcher.js +12 -3
  24. package/dist/src/runtime.d.ts +3 -11
  25. package/dist/src/runtime.js +6 -18
  26. package/dist/src/self-evolution-handler.d.ts +6 -0
  27. package/dist/src/self-evolution-handler.js +100 -7
  28. package/dist/src/self-evolution-keyword.d.ts +9 -0
  29. package/dist/src/self-evolution-keyword.js +147 -0
  30. package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
  31. package/dist/src/self-evolution-tool-result-nudge.js +96 -0
  32. package/dist/src/skill-retriever/config.d.ts +4 -0
  33. package/dist/src/skill-retriever/config.js +23 -0
  34. package/dist/src/skill-retriever/hooks.d.ts +22 -0
  35. package/dist/src/skill-retriever/hooks.js +83 -0
  36. package/dist/src/skill-retriever/tool-search.d.ts +16 -0
  37. package/dist/src/skill-retriever/tool-search.js +173 -0
  38. package/dist/src/skill-retriever/types.d.ts +36 -0
  39. package/dist/src/skill-retriever/types.js +1 -0
  40. package/dist/src/steer-injector.js +1 -1
  41. package/dist/src/task-manager.d.ts +4 -0
  42. package/dist/src/task-manager.js +12 -1
  43. package/dist/src/tools/calendar-tool.d.ts +2 -1
  44. package/dist/src/tools/calendar-tool.js +112 -116
  45. package/dist/src/tools/call-device-tool.d.ts +2 -1
  46. package/dist/src/tools/call-device-tool.js +126 -103
  47. package/dist/src/tools/call-phone-tool.d.ts +2 -1
  48. package/dist/src/tools/call-phone-tool.js +109 -113
  49. package/dist/src/tools/create-alarm-tool.d.ts +2 -1
  50. package/dist/src/tools/create-alarm-tool.js +227 -231
  51. package/dist/src/tools/create-all-tools.d.ts +16 -0
  52. package/dist/src/tools/create-all-tools.js +50 -0
  53. package/dist/src/tools/delete-alarm-tool.d.ts +2 -1
  54. package/dist/src/tools/delete-alarm-tool.js +131 -135
  55. package/dist/src/tools/get-alarm-tool-schema.d.ts +2 -1
  56. package/dist/src/tools/get-alarm-tool-schema.js +16 -10
  57. package/dist/src/tools/get-calendar-tool-schema.d.ts +2 -1
  58. package/dist/src/tools/get-calendar-tool-schema.js +12 -8
  59. package/dist/src/tools/get-collection-tool-schema.d.ts +2 -1
  60. package/dist/src/tools/get-collection-tool-schema.js +11 -9
  61. package/dist/src/tools/get-contact-tool-schema.d.ts +2 -1
  62. package/dist/src/tools/get-contact-tool-schema.js +16 -10
  63. package/dist/src/tools/get-device-file-tool-schema.d.ts +2 -1
  64. package/dist/src/tools/get-device-file-tool-schema.js +13 -9
  65. package/dist/src/tools/get-email-tool-schema.d.ts +2 -1
  66. package/dist/src/tools/get-email-tool-schema.js +11 -8
  67. package/dist/src/tools/get-note-tool-schema.d.ts +2 -1
  68. package/dist/src/tools/get-note-tool-schema.js +14 -9
  69. package/dist/src/tools/get-photo-tool-schema.d.ts +2 -1
  70. package/dist/src/tools/get-photo-tool-schema.js +12 -9
  71. package/dist/src/tools/image-reading-tool.d.ts +2 -1
  72. package/dist/src/tools/image-reading-tool.js +86 -90
  73. package/dist/src/tools/location-tool.d.ts +2 -1
  74. package/dist/src/tools/location-tool.js +87 -91
  75. package/dist/src/tools/login-token-tool.d.ts +6 -0
  76. package/dist/src/tools/login-token-tool.js +133 -0
  77. package/dist/src/tools/modify-alarm-tool.d.ts +2 -1
  78. package/dist/src/tools/modify-alarm-tool.js +232 -236
  79. package/dist/src/tools/modify-note-tool.d.ts +2 -1
  80. package/dist/src/tools/modify-note-tool.js +104 -108
  81. package/dist/src/tools/note-tool.d.ts +2 -1
  82. package/dist/src/tools/note-tool.js +103 -107
  83. package/dist/src/tools/query-app-message-tool.d.ts +2 -1
  84. package/dist/src/tools/query-app-message-tool.js +108 -111
  85. package/dist/src/tools/query-memory-data-tool.d.ts +2 -1
  86. package/dist/src/tools/query-memory-data-tool.js +109 -112
  87. package/dist/src/tools/query-todo-task-tool.d.ts +2 -1
  88. package/dist/src/tools/query-todo-task-tool.js +103 -106
  89. package/dist/src/tools/save-file-to-phone-tool.d.ts +2 -1
  90. package/dist/src/tools/save-file-to-phone-tool.js +127 -131
  91. package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
  92. package/dist/src/tools/save-media-to-gallery-tool.js +134 -138
  93. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +2 -0
  94. package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
  95. package/dist/src/tools/search-alarm-tool.d.ts +2 -1
  96. package/dist/src/tools/search-alarm-tool.js +171 -175
  97. package/dist/src/tools/search-calendar-tool.d.ts +2 -1
  98. package/dist/src/tools/search-calendar-tool.js +145 -149
  99. package/dist/src/tools/search-contact-tool.d.ts +2 -1
  100. package/dist/src/tools/search-contact-tool.js +98 -102
  101. package/dist/src/tools/search-email-tool.d.ts +2 -1
  102. package/dist/src/tools/search-email-tool.js +107 -111
  103. package/dist/src/tools/search-file-tool.d.ts +2 -1
  104. package/dist/src/tools/search-file-tool.js +99 -103
  105. package/dist/src/tools/search-message-tool.d.ts +2 -1
  106. package/dist/src/tools/search-message-tool.js +100 -104
  107. package/dist/src/tools/search-note-tool.d.ts +2 -1
  108. package/dist/src/tools/search-note-tool.js +95 -99
  109. package/dist/src/tools/search-photo-gallery-tool.d.ts +2 -1
  110. package/dist/src/tools/search-photo-gallery-tool.js +34 -38
  111. package/dist/src/tools/send-email-tool.d.ts +2 -1
  112. package/dist/src/tools/send-email-tool.js +105 -108
  113. package/dist/src/tools/send-file-to-user-tool.d.ts +2 -1
  114. package/dist/src/tools/send-file-to-user-tool.js +154 -155
  115. package/dist/src/tools/send-message-tool.d.ts +2 -1
  116. package/dist/src/tools/send-message-tool.js +119 -123
  117. package/dist/src/tools/session-manager.d.ts +21 -6
  118. package/dist/src/tools/session-manager.js +147 -18
  119. package/dist/src/tools/upload-file-tool.d.ts +2 -1
  120. package/dist/src/tools/upload-file-tool.js +78 -82
  121. package/dist/src/tools/upload-photo-tool.d.ts +2 -1
  122. package/dist/src/tools/upload-photo-tool.js +69 -73
  123. package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +2 -1
  124. package/dist/src/tools/xiaoyi-add-collection-tool.js +143 -147
  125. package/dist/src/tools/xiaoyi-collection-tool.d.ts +2 -1
  126. package/dist/src/tools/xiaoyi-collection-tool.js +111 -115
  127. package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +2 -1
  128. package/dist/src/tools/xiaoyi-delete-collection-tool.js +124 -128
  129. package/dist/src/tools/xiaoyi-gui-tool.d.ts +2 -1
  130. package/dist/src/tools/xiaoyi-gui-tool.js +84 -88
  131. package/dist/src/utils/logger.js +20 -18
  132. package/dist/src/utils/runtime-manager.js +24 -2
  133. package/dist/src/utils/self-evolution-manager.d.ts +10 -0
  134. package/dist/src/utils/self-evolution-manager.js +69 -0
  135. package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
  136. package/dist/src/utils/tool-call-nudge-manager.js +47 -0
  137. package/dist/src/websocket.d.ts +3 -0
  138. package/dist/src/websocket.js +91 -26
  139. package/openclaw.plugin.json +22 -0
  140. package/package.json +3 -3
@@ -1,6 +1,5 @@
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 upload file tool - uploads local files to get publicly accessible URLs.
6
5
  * Requires file URIs from search_file tool as prerequisite.
@@ -13,10 +12,12 @@ import { getCurrentSessionContext } from "./session-manager.js";
13
12
  * - After getting public URLs, if further processing is needed, download the file first
14
13
  * - URLs returned are publicly accessible
15
14
  */
16
- export const uploadFileTool = {
17
- name: "upload_file",
18
- label: "Upload File",
19
- description: `工具能力描述:将用户本地设备文件上传并获取可公网访问的 URL。
15
+ export function createUploadFileTool(ctx) {
16
+ const { config, sessionId, taskId, messageId } = ctx;
17
+ return {
18
+ name: "upload_file",
19
+ label: "Upload File",
20
+ description: `工具能力描述:将用户本地设备文件上传并获取可公网访问的 URL。
20
21
 
21
22
  前置工具调用:此工具使用前必须先通过call_device_tool调用 search_file 或者 query_collection 工具获取文件的 uri
22
23
 
@@ -28,92 +29,87 @@ export const uploadFileTool = {
28
29
  注意事项:
29
30
  a. 操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
30
31
  b. 此工具返回的文件链接为用户公网可访问的链接,如果需要对文件进行额外的操作,需要先根据返回的url下载文件,然后进行下一步处理。`,
31
- parameters: {
32
- type: "object",
33
- properties: {
34
- fileInfos: {
35
- // 不指定 type,允许传入数组或 JSON 字符串
36
- // 具体的类型验证和转换在 execute 函数内部进行
37
- description: "文件信息数组,每个元素包含mediaUri(必需)和timeout(可选,默认20000)。必须先通过 search_file 工具获取。每次最多支持 5 条文件信息。",
32
+ parameters: {
33
+ type: "object",
34
+ properties: {
35
+ fileInfos: {
36
+ // 不指定 type,允许传入数组或 JSON 字符串
37
+ // 具体的类型验证和转换在 execute 函数内部进行
38
+ description: "文件信息数组,每个元素包含mediaUri(必需)和timeout(可选,默认20000)。必须先通过 search_file 工具获取。每次最多支持 5 条文件信息。",
39
+ },
38
40
  },
41
+ required: ["fileInfos"],
39
42
  },
40
- required: ["fileInfos"],
41
- },
42
- async execute(toolCallId, params) {
43
- // ===== 参数规范化:兼容数组和 JSON 字符串 =====
44
- let fileInfos = null;
45
- if (!params.fileInfos) {
46
- throw new Error("Missing required parameter: fileInfos");
47
- }
48
- // 情况1: 已经是数组
49
- if (Array.isArray(params.fileInfos)) {
50
- fileInfos = params.fileInfos;
51
- }
52
- // 情况2: 是字符串,尝试解析为 JSON 数组
53
- else if (typeof params.fileInfos === 'string') {
54
- try {
55
- const parsed = JSON.parse(params.fileInfos);
56
- if (Array.isArray(parsed)) {
57
- fileInfos = parsed;
43
+ async execute(toolCallId, params) {
44
+ // ===== 参数规范化:兼容数组和 JSON 字符串 =====
45
+ let fileInfos = null;
46
+ if (!params.fileInfos) {
47
+ throw new Error("Missing required parameter: fileInfos");
48
+ }
49
+ // 情况1: 已经是数组
50
+ if (Array.isArray(params.fileInfos)) {
51
+ fileInfos = params.fileInfos;
52
+ }
53
+ // 情况2: 是字符串,尝试解析为 JSON 数组
54
+ else if (typeof params.fileInfos === 'string') {
55
+ try {
56
+ const parsed = JSON.parse(params.fileInfos);
57
+ if (Array.isArray(parsed)) {
58
+ fileInfos = parsed;
59
+ }
60
+ else {
61
+ throw new Error("fileInfos must be an array or a JSON string representing an array");
62
+ }
58
63
  }
59
- else {
60
- throw new Error("fileInfos must be an array or a JSON string representing an array");
64
+ catch (parseError) {
65
+ throw new Error(`fileInfos must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
61
66
  }
62
67
  }
63
- catch (parseError) {
64
- throw new Error(`fileInfos must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
68
+ // 情况3: 其他类型,报错
69
+ else {
70
+ throw new Error(`fileInfos must be an array or a JSON string, got ${typeof params.fileInfos}`);
65
71
  }
66
- }
67
- // 情况3: 其他类型,报错
68
- else {
69
- throw new Error(`fileInfos must be an array or a JSON string, got ${typeof params.fileInfos}`);
70
- }
71
- // 验证数组非空
72
- if (!fileInfos || fileInfos.length === 0) {
73
- throw new Error("fileInfos array cannot be empty");
74
- }
75
- // Validate maximum 5 file infos
76
- if (fileInfos.length > 5) {
77
- throw new Error(`最多支持 5 条文件信息,当前提供了 ${fileInfos.length} 条。请分批处理。`);
78
- }
79
- // Validate each fileInfo has required mediaUri field
80
- for (let i = 0; i < fileInfos.length; i++) {
81
- const fileInfo = fileInfos[i];
82
- if (!fileInfo || typeof fileInfo !== 'object') {
83
- throw new Error(`fileInfos[${i}] must be an object with mediaUri property`);
72
+ // 验证数组非空
73
+ if (!fileInfos || fileInfos.length === 0) {
74
+ throw new Error("fileInfos array cannot be empty");
84
75
  }
85
- if (!fileInfo.mediaUri || typeof fileInfo.mediaUri !== 'string') {
86
- throw new Error(`fileInfos[${i}] must have a valid mediaUri string property`);
76
+ // Validate maximum 5 file infos
77
+ if (fileInfos.length > 5) {
78
+ throw new Error(`最多支持 5 条文件信息,当前提供了 ${fileInfos.length} 条。请分批处理。`);
87
79
  }
88
- // Set default timeout if not provided
89
- if (!fileInfo.timeout) {
90
- fileInfo.timeout = "20000";
80
+ // Validate each fileInfo has required mediaUri field
81
+ for (let i = 0; i < fileInfos.length; i++) {
82
+ const fileInfo = fileInfos[i];
83
+ if (!fileInfo || typeof fileInfo !== 'object') {
84
+ throw new Error(`fileInfos[${i}] must be an object with mediaUri property`);
85
+ }
86
+ if (!fileInfo.mediaUri || typeof fileInfo.mediaUri !== 'string') {
87
+ throw new Error(`fileInfos[${i}] must have a valid mediaUri string property`);
88
+ }
89
+ // Set default timeout if not provided
90
+ if (!fileInfo.timeout) {
91
+ fileInfo.timeout = "20000";
92
+ }
91
93
  }
92
- }
93
- // Get session context
94
- const sessionContext = getCurrentSessionContext();
95
- if (!sessionContext) {
96
- throw new Error("No active XY session found. Upload file tool can only be used during an active conversation.");
97
- }
98
- const { config, sessionId, taskId, messageId } = sessionContext;
99
- // Get WebSocket manager
100
- const wsManager = getXYWebSocketManager(config);
101
- // Get public URLs for the files
102
- const fileUrls = await getFileUrls(wsManager, config, sessionId, taskId, messageId, fileInfos);
103
- return {
104
- content: [
105
- {
106
- type: "text",
107
- text: JSON.stringify({
108
- fileUrls,
109
- count: fileUrls.length,
110
- message: `成功获取 ${fileUrls.length} 个文件的公网访问 URL`
111
- }),
112
- },
113
- ],
114
- };
115
- },
116
- };
94
+ // Get WebSocket manager
95
+ const wsManager = getXYWebSocketManager(config);
96
+ // Get public URLs for the files
97
+ const fileUrls = await getFileUrls(wsManager, config, sessionId, taskId, messageId, fileInfos);
98
+ return {
99
+ content: [
100
+ {
101
+ type: "text",
102
+ text: JSON.stringify({
103
+ fileUrls,
104
+ count: fileUrls.length,
105
+ message: `成功获取 ${fileUrls.length} 个文件的公网访问 URL`
106
+ }),
107
+ },
108
+ ],
109
+ };
110
+ },
111
+ };
112
+ }
117
113
  /**
118
114
  * Get public URLs for files using fileInfos
119
115
  * Returns array of publicly accessible file URLs
@@ -1,3 +1,4 @@
1
+ import type { SessionContext } from "./session-manager.js";
1
2
  /**
2
3
  * XY upload photo tool - uploads local photos to get publicly accessible URLs.
3
4
  * Requires mediaUris from search_photo_gallery tool as prerequisite.
@@ -6,4 +7,4 @@
6
7
  * 1. Call search_photo_gallery tool first to get mediaUris of photos
7
8
  * 2. Use the mediaUris (maximum 5 at a time) to get public URLs
8
9
  */
9
- export declare const uploadPhotoTool: any;
10
+ export declare function createUploadPhotoTool(ctx: SessionContext): any;
@@ -1,6 +1,5 @@
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 upload photo tool - uploads local photos to get publicly accessible URLs.
6
5
  * Requires mediaUris from search_photo_gallery tool as prerequisite.
@@ -9,92 +8,89 @@ import { getCurrentSessionContext } from "./session-manager.js";
9
8
  * 1. Call search_photo_gallery tool first to get mediaUris of photos
10
9
  * 2. Use the mediaUris (maximum 5 at a time) to get public URLs
11
10
  */
12
- export const uploadPhotoTool = {
13
- name: "upload_photo",
14
- label: "Upload Photo",
15
- description: `工具能力描述:将用户本地设备文件回传并获取可公网访问的 URL。
16
-
11
+ export function createUploadPhotoTool(ctx) {
12
+ const { config, sessionId, taskId, messageId } = ctx;
13
+ return {
14
+ name: "upload_photo",
15
+ label: "Upload Photo",
16
+ description: `工具能力描述:将用户本地设备文件回传并获取可公网访问的 URL。
17
+
17
18
  前置工具调用:此工具使用前必须先通过call_device_tool工具调用 search_photo_gallery 工具获取照片的 mediaUri或者thumbnailUri
18
19
  工具参数说明:
19
20
  a. 入参中的mediaUris中的mediaUri必须与search_photo_gallery结果中对应的mediaUri或者thumbnailUri完全保持一致,不要自行修改,必须是file:://开头的路径。
20
21
  b. 优先使用search_photo_gallery结果中的thumbnailUri作为入参,thumbnailUri是缩略图,清晰度与文件大小都非常合适展示给用户,如果thumbnailUri不存在或者用户要求使用原图,则使用search_photo_gallery结果中对应的mediaUri
21
22
  c. mediaUris 是照片在手机本地的 URI 数组(从 search_photo_gallery 工具响应中获取)。限制:每次最多支持传入 3 条 mediaUri。
22
-
23
+
23
24
  注意事项:
24
25
  a. 操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
25
26
  b. 此工具返回的图片链接为用户公网可访问的链接,如果需要后续操作需要下载到本地,如果需要返回给用户查看则直接以图片markdown的形式返回给用户`,
26
- parameters: {
27
- type: "object",
28
- properties: {
29
- mediaUris: {
30
- // 不指定 type,允许传入数组或 JSON 字符串
31
- // 具体的类型验证和转换在 execute 函数内部进行
32
- description: "照片在手机本地的 URI 数组,必须先通过 search_photo_gallery 工具获取。每次最多支持 3 条 URI。",
27
+ parameters: {
28
+ type: "object",
29
+ properties: {
30
+ mediaUris: {
31
+ // 不指定 type,允许传入数组或 JSON 字符串
32
+ // 具体的类型验证和转换在 execute 函数内部进行
33
+ description: "照片在手机本地的 URI 数组,必须先通过 search_photo_gallery 工具获取。每次最多支持 3 条 URI。",
34
+ },
33
35
  },
36
+ required: ["mediaUris"],
34
37
  },
35
- required: ["mediaUris"],
36
- },
37
- async execute(toolCallId, params) {
38
- // ===== 参数规范化:兼容数组和 JSON 字符串 =====
39
- let mediaUris = null;
40
- if (!params.mediaUris) {
41
- throw new Error("Missing required parameter: mediaUris");
42
- }
43
- // 情况1: 已经是数组
44
- if (Array.isArray(params.mediaUris)) {
45
- mediaUris = params.mediaUris;
46
- }
47
- // 情况2: 是字符串,尝试解析为 JSON 数组
48
- else if (typeof params.mediaUris === 'string') {
49
- try {
50
- const parsed = JSON.parse(params.mediaUris);
51
- if (Array.isArray(parsed)) {
52
- mediaUris = parsed;
38
+ async execute(toolCallId, params) {
39
+ // ===== 参数规范化:兼容数组和 JSON 字符串 =====
40
+ let mediaUris = null;
41
+ if (!params.mediaUris) {
42
+ throw new Error("Missing required parameter: mediaUris");
43
+ }
44
+ // 情况1: 已经是数组
45
+ if (Array.isArray(params.mediaUris)) {
46
+ mediaUris = params.mediaUris;
47
+ }
48
+ // 情况2: 是字符串,尝试解析为 JSON 数组
49
+ else if (typeof params.mediaUris === 'string') {
50
+ try {
51
+ const parsed = JSON.parse(params.mediaUris);
52
+ if (Array.isArray(parsed)) {
53
+ mediaUris = parsed;
54
+ }
55
+ else {
56
+ throw new Error("mediaUris must be an array or a JSON string representing an array");
57
+ }
53
58
  }
54
- else {
55
- throw new Error("mediaUris must be an array or a JSON string representing an array");
59
+ catch (parseError) {
60
+ throw new Error(`mediaUris must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
56
61
  }
57
62
  }
58
- catch (parseError) {
59
- throw new Error(`mediaUris must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
63
+ // 情况3: 其他类型,报错
64
+ else {
65
+ throw new Error(`mediaUris must be an array or a JSON string, got ${typeof params.mediaUris}`);
60
66
  }
61
- }
62
- // 情况3: 其他类型,报错
63
- else {
64
- throw new Error(`mediaUris must be an array or a JSON string, got ${typeof params.mediaUris}`);
65
- }
66
- // 验证数组非空
67
- if (!mediaUris || mediaUris.length === 0) {
68
- throw new Error("mediaUris array cannot be empty");
69
- }
70
- // Validate maximum 5 URIs
71
- if (mediaUris.length > 5) {
72
- throw new Error(`最多支持 5 条 mediaUri,当前提供了 ${mediaUris.length} 条。请分批处理。`);
73
- }
74
- // Get session context
75
- const sessionContext = getCurrentSessionContext();
76
- if (!sessionContext) {
77
- throw new Error("No active XY session found. Upload photo tool can only be used during an active conversation.");
78
- }
79
- const { config, sessionId, taskId, messageId } = sessionContext;
80
- // Get WebSocket manager
81
- const wsManager = getXYWebSocketManager(config);
82
- // Get public URLs for the photos
83
- const imageUrls = await getPhotoUrls(wsManager, config, sessionId, taskId, messageId, mediaUris);
84
- return {
85
- content: [
86
- {
87
- type: "text",
88
- text: JSON.stringify({
89
- imageUrls,
90
- count: imageUrls.length,
91
- message: `成功获取 ${imageUrls.length} 张照片的公网访问 URL`
92
- }),
93
- },
94
- ],
95
- };
96
- },
97
- };
67
+ // 验证数组非空
68
+ if (!mediaUris || mediaUris.length === 0) {
69
+ throw new Error("mediaUris array cannot be empty");
70
+ }
71
+ // Validate maximum 5 URIs
72
+ if (mediaUris.length > 5) {
73
+ throw new Error(`最多支持 5 条 mediaUri,当前提供了 ${mediaUris.length} 条。请分批处理。`);
74
+ }
75
+ // Get WebSocket manager
76
+ const wsManager = getXYWebSocketManager(config);
77
+ // Get public URLs for the photos
78
+ const imageUrls = await getPhotoUrls(wsManager, config, sessionId, taskId, messageId, mediaUris);
79
+ return {
80
+ content: [
81
+ {
82
+ type: "text",
83
+ text: JSON.stringify({
84
+ imageUrls,
85
+ count: imageUrls.length,
86
+ message: `成功获取 ${imageUrls.length} 张照片的公网访问 URL`
87
+ }),
88
+ },
89
+ ],
90
+ };
91
+ },
92
+ };
93
+ }
98
94
  /**
99
95
  * Get public URLs for photos using mediaUris
100
96
  * Returns array of publicly accessible image URLs
@@ -1,4 +1,5 @@
1
+ import type { SessionContext } from "./session-manager.js";
1
2
  /**
2
3
  * XY add collection tool - adds data to user's XiaoYi collection.
3
4
  */
4
- export declare const xiaoyiAddCollectionTool: any;
5
+ export declare function createXiaoyiAddCollectionTool(ctx: SessionContext): any;