@ynhcj/xiaoyi-channel 0.0.89-beta → 0.0.89-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 (135) hide show
  1. package/dist/index.d.ts +6 -9
  2. package/dist/index.js +26 -21
  3. package/dist/src/bot.js +27 -4
  4. package/dist/src/channel.js +2 -16
  5. package/dist/src/client.js +31 -22
  6. package/dist/src/cspl/call-api.js +6 -5
  7. package/dist/src/file-download.js +4 -3
  8. package/dist/src/file-upload.js +19 -18
  9. package/dist/src/heartbeat.js +1 -1
  10. package/dist/src/login-token-handler.d.ts +8 -0
  11. package/dist/src/login-token-handler.js +60 -0
  12. package/dist/src/message-queue.d.ts +17 -0
  13. package/dist/src/message-queue.js +51 -0
  14. package/dist/src/monitor.js +75 -13
  15. package/dist/src/outbound.js +19 -18
  16. package/dist/src/provider.d.ts +2 -1
  17. package/dist/src/provider.js +443 -34
  18. package/dist/src/push.js +16 -15
  19. package/dist/src/reply-dispatcher.js +4 -3
  20. package/dist/src/runtime.d.ts +3 -11
  21. package/dist/src/runtime.js +6 -18
  22. package/dist/src/self-evolution-handler.d.ts +7 -0
  23. package/dist/src/self-evolution-handler.js +140 -0
  24. package/dist/src/self-evolution-keyword.d.ts +9 -0
  25. package/dist/src/self-evolution-keyword.js +147 -0
  26. package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
  27. package/dist/src/self-evolution-tool-result-nudge.js +96 -0
  28. package/dist/src/skill-retriever/config.d.ts +4 -0
  29. package/dist/src/skill-retriever/config.js +23 -0
  30. package/dist/src/skill-retriever/hooks.d.ts +22 -0
  31. package/dist/src/skill-retriever/hooks.js +83 -0
  32. package/dist/src/skill-retriever/tool-search.d.ts +16 -0
  33. package/dist/src/skill-retriever/tool-search.js +173 -0
  34. package/dist/src/skill-retriever/types.d.ts +36 -0
  35. package/dist/src/skill-retriever/types.js +1 -0
  36. package/dist/src/steer-injector.js +1 -1
  37. package/dist/src/task-manager.d.ts +4 -0
  38. package/dist/src/task-manager.js +12 -1
  39. package/dist/src/tools/calendar-tool.d.ts +2 -1
  40. package/dist/src/tools/calendar-tool.js +112 -116
  41. package/dist/src/tools/call-device-tool.d.ts +2 -1
  42. package/dist/src/tools/call-device-tool.js +126 -99
  43. package/dist/src/tools/call-phone-tool.d.ts +2 -1
  44. package/dist/src/tools/call-phone-tool.js +109 -113
  45. package/dist/src/tools/create-alarm-tool.d.ts +2 -1
  46. package/dist/src/tools/create-alarm-tool.js +227 -231
  47. package/dist/src/tools/create-all-tools.d.ts +16 -0
  48. package/dist/src/tools/create-all-tools.js +50 -0
  49. package/dist/src/tools/delete-alarm-tool.d.ts +2 -1
  50. package/dist/src/tools/delete-alarm-tool.js +131 -135
  51. package/dist/src/tools/get-alarm-tool-schema.d.ts +2 -1
  52. package/dist/src/tools/get-alarm-tool-schema.js +16 -10
  53. package/dist/src/tools/get-calendar-tool-schema.d.ts +2 -1
  54. package/dist/src/tools/get-calendar-tool-schema.js +12 -8
  55. package/dist/src/tools/get-collection-tool-schema.d.ts +2 -1
  56. package/dist/src/tools/get-collection-tool-schema.js +11 -9
  57. package/dist/src/tools/get-contact-tool-schema.d.ts +2 -1
  58. package/dist/src/tools/get-contact-tool-schema.js +16 -10
  59. package/dist/src/tools/get-device-file-tool-schema.d.ts +2 -1
  60. package/dist/src/tools/get-device-file-tool-schema.js +13 -9
  61. package/dist/src/tools/get-email-tool-schema.d.ts +17 -0
  62. package/dist/src/tools/get-email-tool-schema.js +12 -0
  63. package/dist/src/tools/get-note-tool-schema.d.ts +2 -1
  64. package/dist/src/tools/get-note-tool-schema.js +14 -9
  65. package/dist/src/tools/get-photo-tool-schema.d.ts +2 -1
  66. package/dist/src/tools/get-photo-tool-schema.js +12 -9
  67. package/dist/src/tools/image-reading-tool.d.ts +2 -1
  68. package/dist/src/tools/image-reading-tool.js +86 -90
  69. package/dist/src/tools/location-tool.d.ts +2 -1
  70. package/dist/src/tools/location-tool.js +87 -91
  71. package/dist/src/tools/login-token-tool.d.ts +6 -0
  72. package/dist/src/tools/login-token-tool.js +133 -0
  73. package/dist/src/tools/modify-alarm-tool.d.ts +2 -1
  74. package/dist/src/tools/modify-alarm-tool.js +232 -236
  75. package/dist/src/tools/modify-note-tool.d.ts +2 -1
  76. package/dist/src/tools/modify-note-tool.js +104 -108
  77. package/dist/src/tools/note-tool.d.ts +2 -1
  78. package/dist/src/tools/note-tool.js +103 -107
  79. package/dist/src/tools/query-app-message-tool.d.ts +5 -0
  80. package/dist/src/tools/query-app-message-tool.js +135 -0
  81. package/dist/src/tools/query-memory-data-tool.d.ts +5 -0
  82. package/dist/src/tools/query-memory-data-tool.js +151 -0
  83. package/dist/src/tools/query-todo-task-tool.d.ts +5 -0
  84. package/dist/src/tools/query-todo-task-tool.js +130 -0
  85. package/dist/src/tools/save-file-to-phone-tool.d.ts +2 -1
  86. package/dist/src/tools/save-file-to-phone-tool.js +127 -131
  87. package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
  88. package/dist/src/tools/save-media-to-gallery-tool.js +134 -138
  89. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +2 -0
  90. package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
  91. package/dist/src/tools/search-alarm-tool.d.ts +2 -1
  92. package/dist/src/tools/search-alarm-tool.js +171 -175
  93. package/dist/src/tools/search-calendar-tool.d.ts +2 -1
  94. package/dist/src/tools/search-calendar-tool.js +145 -149
  95. package/dist/src/tools/search-contact-tool.d.ts +2 -1
  96. package/dist/src/tools/search-contact-tool.js +98 -102
  97. package/dist/src/tools/search-email-tool.d.ts +2 -1
  98. package/dist/src/tools/search-email-tool.js +107 -111
  99. package/dist/src/tools/search-file-tool.d.ts +2 -1
  100. package/dist/src/tools/search-file-tool.js +99 -103
  101. package/dist/src/tools/search-message-tool.d.ts +2 -1
  102. package/dist/src/tools/search-message-tool.js +100 -104
  103. package/dist/src/tools/search-note-tool.d.ts +2 -1
  104. package/dist/src/tools/search-note-tool.js +95 -99
  105. package/dist/src/tools/search-photo-gallery-tool.d.ts +2 -1
  106. package/dist/src/tools/search-photo-gallery-tool.js +34 -38
  107. package/dist/src/tools/send-email-tool.d.ts +5 -0
  108. package/dist/src/tools/send-email-tool.js +131 -0
  109. package/dist/src/tools/send-file-to-user-tool.d.ts +2 -1
  110. package/dist/src/tools/send-file-to-user-tool.js +154 -155
  111. package/dist/src/tools/send-message-tool.d.ts +2 -1
  112. package/dist/src/tools/send-message-tool.js +119 -123
  113. package/dist/src/tools/session-manager.d.ts +21 -6
  114. package/dist/src/tools/session-manager.js +147 -18
  115. package/dist/src/tools/upload-file-tool.d.ts +2 -1
  116. package/dist/src/tools/upload-file-tool.js +78 -82
  117. package/dist/src/tools/upload-photo-tool.d.ts +2 -1
  118. package/dist/src/tools/upload-photo-tool.js +69 -73
  119. package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +2 -1
  120. package/dist/src/tools/xiaoyi-add-collection-tool.js +143 -147
  121. package/dist/src/tools/xiaoyi-collection-tool.d.ts +2 -1
  122. package/dist/src/tools/xiaoyi-collection-tool.js +111 -115
  123. package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +2 -1
  124. package/dist/src/tools/xiaoyi-delete-collection-tool.js +124 -128
  125. package/dist/src/tools/xiaoyi-gui-tool.d.ts +2 -1
  126. package/dist/src/tools/xiaoyi-gui-tool.js +84 -88
  127. package/dist/src/utils/runtime-manager.js +24 -2
  128. package/dist/src/utils/self-evolution-manager.d.ts +10 -0
  129. package/dist/src/utils/self-evolution-manager.js +69 -0
  130. package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
  131. package/dist/src/utils/tool-call-nudge-manager.js +47 -0
  132. package/dist/src/websocket.d.ts +3 -0
  133. package/dist/src/websocket.js +97 -25
  134. package/openclaw.plugin.json +21 -0
  135. 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
  import { XYFileUploadService } from "../file-upload.js";
5
4
  /**
6
5
  * Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
@@ -17,10 +16,12 @@ class ToolInputError extends Error {
17
16
  /**
18
17
  * XY add collection tool - adds data to user's XiaoYi collection.
19
18
  */
20
- export const xiaoyiAddCollectionTool = {
21
- name: "add_collection",
22
- label: "Add XiaoYi Collection",
23
- description: `向小艺收藏中添加公共知识数据,可以给用户提供个性化体验。任何用户希望保存到个人化知识库中的数据都可以调用本技能。不同类型的数据对应的数据要求如下:
19
+ export function createXiaoyiAddCollectionTool(ctx) {
20
+ const { config, sessionId, taskId, messageId } = ctx;
21
+ return {
22
+ name: "add_collection",
23
+ label: "Add XiaoYi Collection",
24
+ description: `向小艺收藏中添加公共知识数据,可以给用户提供个性化体验。任何用户希望保存到个人化知识库中的数据都可以调用本技能。不同类型的数据对应的数据要求如下:
24
25
  请求入参说明:
25
26
  ● content:必填字段,数据类型为string,功能描述是该字段是用户添加收藏的链接url或文本原文。适用于HYPER_LINK和TEXT类型。
26
27
  ● uri:必填字段,数据类型为string,功能描述是该字段是图片或文件的端存储地址链接。适用于IMAGE和FILE类型。
@@ -36,157 +37,152 @@ export const xiaoyiAddCollectionTool = {
36
37
 
37
38
  回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
38
39
  `,
39
- parameters: {
40
- type: "object",
41
- properties: {
42
- content: {
43
- type: "string",
44
- description: "必填字段(HYPER_LINK/TEXT类型时)。用户添加收藏的链接url或文本原文。",
45
- },
46
- uri: {
47
- type: "string",
48
- description: `必填字段(IMAGE/FILE类型时)。图片或文件的地址链接。
40
+ parameters: {
41
+ type: "object",
42
+ properties: {
43
+ content: {
44
+ type: "string",
45
+ description: "必填字段(HYPER_LINK/TEXT类型时)。用户添加收藏的链接url或文本原文。",
46
+ },
47
+ uri: {
48
+ type: "string",
49
+ description: `必填字段(IMAGE/FILE类型时)。图片或文件的地址链接。
49
50
  uri具备三种严格的格式
50
51
  (1) http或者https开头的公网链接,一般是用户通过联网搜索获取的文件地址,不允许自行编造,此类链接填入时必须确保真实
51
52
  (2) file://开头的链接,此类链接必须来源于query_collection结果或者search_file或者search_photo_gallery的结果,不允许自行编造
52
53
  (3) 本地路径例,如/tmp/xy_channel/xxx,此类路径是文件保存在当前openclaw运行环境的本地目录,可以直接填入,不要擅自拼接http://或者file://前缀`,
54
+ },
55
+ sourceAppBundleName: {
56
+ type: "string",
57
+ description: "非必填字段。标识该数据的来源应用。",
58
+ },
59
+ dataType: {
60
+ type: "string",
61
+ description: "必填字段。标识数据类型:HYPER_LINK表示网页,TEXT表示文本,IMAGE表示图片,FILE表示文件。",
62
+ },
63
+ title: {
64
+ type: "string",
65
+ description: "非必填字段。标识文件类型数据的文件名称。适用于FILE类型。",
66
+ },
53
67
  },
54
- sourceAppBundleName: {
55
- type: "string",
56
- description: "非必填字段。标识该数据的来源应用。",
57
- },
58
- dataType: {
59
- type: "string",
60
- description: "必填字段。标识数据类型:HYPER_LINK表示网页,TEXT表示文本,IMAGE表示图片,FILE表示文件。",
61
- },
62
- title: {
63
- type: "string",
64
- description: "非必填字段。标识文件类型数据的文件名称。适用于FILE类型。",
65
- },
68
+ required: ["dataType"],
66
69
  },
67
- required: ["dataType"],
68
- },
69
- async execute(toolCallId, params) {
70
- // Validate parameters
71
- const { content, uri, sourceAppBundleName, dataType, title } = params;
72
- const validTypes = ["HYPER_LINK", "TEXT", "IMAGE", "FILE"];
73
- if (!dataType || !validTypes.includes(dataType)) {
74
- throw new ToolInputError(`dataType必填且必须为 HYPER_LINK、TEXT、IMAGE、FILE 之一,当前值: ${dataType}`);
75
- }
76
- if ((dataType === "HYPER_LINK" || dataType === "TEXT") && (!content || typeof content !== "string")) {
77
- throw new ToolInputError(`dataType为${dataType}时,content字段必填且不能为空`);
78
- }
79
- if ((dataType === "IMAGE" || dataType === "FILE") && (!uri || typeof uri !== "string")) {
80
- throw new ToolInputError(`dataType为${dataType}时,uri字段必填且不能为空`);
81
- }
82
- // Get session context
83
- const sessionContext = getCurrentSessionContext();
84
- if (!sessionContext) {
85
- throw new Error("No active XY session found. AddCollection tool can only be used during an active conversation.");
86
- }
87
- const { config, sessionId, taskId, messageId } = sessionContext;
88
- // Get WebSocket manager
89
- const wsManager = getXYWebSocketManager(config);
90
- // Handle uri: upload local paths to get public URL
91
- let publicUri = uri;
92
- if (uri && !uri.startsWith("http://") && !uri.startsWith("https://") && !uri.startsWith("file://")) {
93
- const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
94
- publicUri = await uploadService.uploadFileAndGetUrl(uri);
95
- if (!publicUri) {
96
- throw new Error("本地文件上传失败,无法获取公网URL");
70
+ async execute(toolCallId, params) {
71
+ // Validate parameters
72
+ const { content, uri, sourceAppBundleName, dataType, title } = params;
73
+ const validTypes = ["HYPER_LINK", "TEXT", "IMAGE", "FILE"];
74
+ if (!dataType || !validTypes.includes(dataType)) {
75
+ throw new ToolInputError(`dataType必填且必须为 HYPER_LINK、TEXT、IMAGE、FILE 之一,当前值: ${dataType}`);
97
76
  }
98
- }
99
- // Build intentParam
100
- const intentParam = {
101
- dataType,
102
- };
103
- if (content) {
104
- intentParam.content = content;
105
- }
106
- if (publicUri) {
107
- intentParam.uri = publicUri;
108
- }
109
- if (sourceAppBundleName) {
110
- intentParam.sourceAppBundleName = sourceAppBundleName;
111
- }
112
- if (title) {
113
- intentParam.title = title;
114
- }
115
- // Build AddCollection command
116
- const command = {
117
- header: {
118
- namespace: "Common",
119
- name: "Action",
120
- },
121
- payload: {
122
- cardParam: {},
123
- executeParam: {
124
- executeMode: "background",
125
- intentName: "AddCollection",
126
- bundleName: "com.huawei.hmos.vassistant",
127
- needUnlock: true,
128
- actionResponse: true,
129
- appType: "OHOS_APP",
130
- timeOut: 5,
131
- intentParam,
132
- permissionId: [],
133
- achieveType: "INTENT",
77
+ if ((dataType === "HYPER_LINK" || dataType === "TEXT") && (!content || typeof content !== "string")) {
78
+ throw new ToolInputError(`dataType为${dataType}时,content字段必填且不能为空`);
79
+ }
80
+ if ((dataType === "IMAGE" || dataType === "FILE") && (!uri || typeof uri !== "string")) {
81
+ throw new ToolInputError(`dataType为${dataType}时,uri字段必填且不能为空`);
82
+ }
83
+ // Get WebSocket manager
84
+ const wsManager = getXYWebSocketManager(config);
85
+ // Handle uri: upload local paths to get public URL
86
+ let publicUri = uri;
87
+ if (uri && !uri.startsWith("http://") && !uri.startsWith("https://") && !uri.startsWith("file://")) {
88
+ const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
89
+ publicUri = await uploadService.uploadFileAndGetUrl(uri);
90
+ if (!publicUri) {
91
+ throw new Error("本地文件上传失败,无法获取公网URL");
92
+ }
93
+ }
94
+ // Build intentParam
95
+ const intentParam = {
96
+ dataType,
97
+ };
98
+ if (content) {
99
+ intentParam.content = content;
100
+ }
101
+ if (publicUri) {
102
+ intentParam.uri = publicUri;
103
+ }
104
+ if (sourceAppBundleName) {
105
+ intentParam.sourceAppBundleName = sourceAppBundleName;
106
+ }
107
+ if (title) {
108
+ intentParam.title = title;
109
+ }
110
+ // Build AddCollection command
111
+ const command = {
112
+ header: {
113
+ namespace: "Common",
114
+ name: "Action",
134
115
  },
135
- responses: [
136
- {
137
- resultCode: "",
138
- displayText: "",
139
- ttsText: "",
116
+ payload: {
117
+ cardParam: {},
118
+ executeParam: {
119
+ executeMode: "background",
120
+ intentName: "AddCollection",
121
+ bundleName: "com.huawei.hmos.vassistant",
122
+ needUnlock: true,
123
+ actionResponse: true,
124
+ appType: "OHOS_APP",
125
+ timeOut: 5,
126
+ intentParam,
127
+ permissionId: [],
128
+ achieveType: "INTENT",
140
129
  },
141
- ],
142
- needUploadResult: true,
143
- noHalfPage: false,
144
- pageControlRelated: false,
145
- },
146
- };
147
- // Send command and wait for response (60 second timeout)
148
- return new Promise((resolve, reject) => {
149
- const timeout = setTimeout(() => {
150
- wsManager.off("data-event", handler);
151
- reject(new Error("添加小艺收藏超时(60秒)"));
152
- }, 60000);
153
- // Listen for data events from WebSocket
154
- const handler = (event) => {
155
- if (event.intentName === "AddCollection") {
156
- clearTimeout(timeout);
130
+ responses: [
131
+ {
132
+ resultCode: "",
133
+ displayText: "",
134
+ ttsText: "",
135
+ },
136
+ ],
137
+ needUploadResult: true,
138
+ noHalfPage: false,
139
+ pageControlRelated: false,
140
+ },
141
+ };
142
+ // Send command and wait for response (60 second timeout)
143
+ return new Promise((resolve, reject) => {
144
+ const timeout = setTimeout(() => {
157
145
  wsManager.off("data-event", handler);
158
- if (event.status === "success" && event.outputs) {
159
- resolve({
160
- content: [
161
- {
162
- type: "text",
163
- text: JSON.stringify(event.outputs),
164
- }
165
- ]
166
- });
146
+ reject(new Error("添加小艺收藏超时(60秒)"));
147
+ }, 60000);
148
+ // Listen for data events from WebSocket
149
+ const handler = (event) => {
150
+ if (event.intentName === "AddCollection") {
151
+ clearTimeout(timeout);
152
+ wsManager.off("data-event", handler);
153
+ if (event.status === "success" && event.outputs) {
154
+ resolve({
155
+ content: [
156
+ {
157
+ type: "text",
158
+ text: JSON.stringify(event.outputs),
159
+ }
160
+ ]
161
+ });
162
+ }
163
+ else {
164
+ reject(new Error(`添加小艺收藏失败: ${event.status}`));
165
+ }
167
166
  }
168
- else {
169
- reject(new Error(`添加小艺收藏失败: ${event.status}`));
170
- }
171
- }
172
- };
173
- // Register event handler
174
- wsManager.on("data-event", handler);
175
- // Send the command
176
- sendCommand({
177
- config,
178
- sessionId,
179
- taskId,
180
- messageId,
181
- command,
182
- })
183
- .then(() => {
184
- })
185
- .catch((error) => {
186
- clearTimeout(timeout);
187
- wsManager.off("data-event", handler);
188
- reject(error);
167
+ };
168
+ // Register event handler
169
+ wsManager.on("data-event", handler);
170
+ // Send the command
171
+ sendCommand({
172
+ config,
173
+ sessionId,
174
+ taskId,
175
+ messageId,
176
+ command,
177
+ })
178
+ .then(() => {
179
+ })
180
+ .catch((error) => {
181
+ clearTimeout(timeout);
182
+ wsManager.off("data-event", handler);
183
+ reject(error);
184
+ });
189
185
  });
190
- });
191
- },
192
- };
186
+ },
187
+ };
188
+ }
@@ -1,5 +1,6 @@
1
+ import type { SessionContext } from "./session-manager.js";
1
2
  /**
2
3
  * XY collection tool - retrieves user's collection data from XiaoYi.
3
4
  * Returns personalized knowledge data saved in user's collection.
4
5
  */
5
- export declare const xiaoyiCollectionTool: any;
6
+ export declare function createXiaoyiCollectionTool(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
  * Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
6
5
  * 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
@@ -17,10 +16,12 @@ class ToolInputError extends Error {
17
16
  * XY collection tool - retrieves user's collection data from XiaoYi.
18
17
  * Returns personalized knowledge data saved in user's collection.
19
18
  */
20
- export const xiaoyiCollectionTool = {
21
- name: "query_collection",
22
- label: "XiaoYi Collection",
23
- description: `检索用户在小艺收藏中记下来的公共知识数据,本技能支持查询用户收藏的公共知识数据,也可以根据特定语义化描述进行特定内容的检索,通过参数进行控制。本技能返回结果中,linkTitle是收藏内容的标题,description是对收藏内容的总结,label是收藏内容的标签,linkUrl是可以直接访问的原始内容链接。如果你认为某条数据对用户交互有用,可以通过linkUrl抓取更加丰富的原始数据。
19
+ export function createXiaoyiCollectionTool(ctx) {
20
+ const { config, sessionId, taskId, messageId } = ctx;
21
+ return {
22
+ name: "query_collection",
23
+ label: "XiaoYi Collection",
24
+ description: `检索用户在小艺收藏中记下来的公共知识数据,本技能支持查询用户收藏的公共知识数据,也可以根据特定语义化描述进行特定内容的检索,通过参数进行控制。本技能返回结果中,linkTitle是收藏内容的标题,description是对收藏内容的总结,label是收藏内容的标签,linkUrl是可以直接访问的原始内容链接。如果你认为某条数据对用户交互有用,可以通过linkUrl抓取更加丰富的原始数据。
24
25
  注意:
25
26
  a. 操作超时时间为60秒,请勿重复调用此工具
26
27
  b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
@@ -29,120 +30,115 @@ export const xiaoyiCollectionTool = {
29
30
 
30
31
  回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
31
32
  `,
32
- parameters: {
33
- type: "object",
34
- properties: {
35
- queryAll: {
36
- type: "string",
37
- description: "非必填参数,描述是否需要查询用户所有收藏数据。如果填入true则表示获取用户所有公共知识数据,其他参数无效。",
38
- },
39
- query: {
40
- type: "string",
41
- description: "非必填参数,queryAll不填或者为false则必填。用户的查询条件,可按照用户query进行检索。",
33
+ parameters: {
34
+ type: "object",
35
+ properties: {
36
+ queryAll: {
37
+ type: "string",
38
+ description: "非必填参数,描述是否需要查询用户所有收藏数据。如果填入true则表示获取用户所有公共知识数据,其他参数无效。",
39
+ },
40
+ query: {
41
+ type: "string",
42
+ description: "非必填参数,queryAll不填或者为false则必填。用户的查询条件,可按照用户query进行检索。",
43
+ },
42
44
  },
45
+ required: [],
43
46
  },
44
- required: [],
45
- },
46
- async execute(toolCallId, params) {
47
- // Validate parameters
48
- const queryAll = params.queryAll;
49
- const query = params.query;
50
- if (queryAll !== "true" && (!query || typeof query !== "string")) {
51
- throw new ToolInputError("queryAll不为true时,query参数必填");
52
- }
53
- // Get session context
54
- const sessionContext = getCurrentSessionContext();
55
- if (!sessionContext) {
56
- throw new Error("No active XY session found. XiaoYi collection tool can only be used during an active conversation.");
57
- }
58
- const { config, sessionId, taskId, messageId } = sessionContext;
59
- // Get WebSocket manager
60
- const wsManager = getXYWebSocketManager(config);
61
- // Build intentParam
62
- const intentParam = {};
63
- if (queryAll === "true") {
64
- intentParam.queryAll = "true";
65
- }
66
- else {
67
- intentParam.queryAll = "false";
68
- intentParam.query = query;
69
- }
70
- // Build QueryCollection command
71
- const command = {
72
- header: {
73
- namespace: "Common",
74
- name: "Action",
75
- },
76
- payload: {
77
- cardParam: {},
78
- executeParam: {
79
- executeMode: "background",
80
- intentName: "QueryCollection",
81
- bundleName: "com.huawei.hmos.vassistant",
82
- needUnlock: true,
83
- actionResponse: true,
84
- appType: "OHOS_APP",
85
- timeOut: 5,
86
- intentParam,
87
- permissionId: [],
88
- achieveType: "INTENT",
47
+ async execute(toolCallId, params) {
48
+ // Validate parameters
49
+ const queryAll = params.queryAll;
50
+ const query = params.query;
51
+ if (queryAll !== "true" && (!query || typeof query !== "string")) {
52
+ throw new ToolInputError("queryAll不为true时,query参数必填");
53
+ }
54
+ // Get WebSocket manager
55
+ const wsManager = getXYWebSocketManager(config);
56
+ // Build intentParam
57
+ const intentParam = {};
58
+ if (queryAll === "true") {
59
+ intentParam.queryAll = "true";
60
+ }
61
+ else {
62
+ intentParam.queryAll = "false";
63
+ intentParam.query = query;
64
+ }
65
+ // Build QueryCollection command
66
+ const command = {
67
+ header: {
68
+ namespace: "Common",
69
+ name: "Action",
89
70
  },
90
- responses: [
91
- {
92
- resultCode: "",
93
- displayText: "",
94
- ttsText: "",
71
+ payload: {
72
+ cardParam: {},
73
+ executeParam: {
74
+ executeMode: "background",
75
+ intentName: "QueryCollection",
76
+ bundleName: "com.huawei.hmos.vassistant",
77
+ needUnlock: true,
78
+ actionResponse: true,
79
+ appType: "OHOS_APP",
80
+ timeOut: 5,
81
+ intentParam,
82
+ permissionId: [],
83
+ achieveType: "INTENT",
95
84
  },
96
- ],
97
- needUploadResult: true,
98
- noHalfPage: false,
99
- pageControlRelated: false,
100
- },
101
- };
102
- // Send command and wait for response (60 second timeout)
103
- return new Promise((resolve, reject) => {
104
- const timeout = setTimeout(() => {
105
- wsManager.off("data-event", handler);
106
- reject(new Error("查询小艺收藏超时(60秒)"));
107
- }, 60000);
108
- // Listen for data events from WebSocket
109
- const handler = (event) => {
110
- if (event.intentName === "QueryCollection") {
111
- clearTimeout(timeout);
85
+ responses: [
86
+ {
87
+ resultCode: "",
88
+ displayText: "",
89
+ ttsText: "",
90
+ },
91
+ ],
92
+ needUploadResult: true,
93
+ noHalfPage: false,
94
+ pageControlRelated: false,
95
+ },
96
+ };
97
+ // Send command and wait for response (60 second timeout)
98
+ return new Promise((resolve, reject) => {
99
+ const timeout = setTimeout(() => {
112
100
  wsManager.off("data-event", handler);
113
- if (event.status === "success" && event.outputs) {
114
- // 成功,直接返回完整的 event.outputs JSON 字符串
115
- resolve({
116
- content: [
117
- {
118
- type: "text",
119
- text: JSON.stringify(event.outputs),
120
- }
121
- ]
122
- });
123
- }
124
- else {
125
- reject(new Error(`查询小艺收藏失败: ${event.status}`));
101
+ reject(new Error("查询小艺收藏超时(60秒)"));
102
+ }, 60000);
103
+ // Listen for data events from WebSocket
104
+ const handler = (event) => {
105
+ if (event.intentName === "QueryCollection") {
106
+ clearTimeout(timeout);
107
+ wsManager.off("data-event", handler);
108
+ if (event.status === "success" && event.outputs) {
109
+ // 成功,直接返回完整的 event.outputs JSON 字符串
110
+ resolve({
111
+ content: [
112
+ {
113
+ type: "text",
114
+ text: JSON.stringify(event.outputs),
115
+ }
116
+ ]
117
+ });
118
+ }
119
+ else {
120
+ reject(new Error(`查询小艺收藏失败: ${event.status}`));
121
+ }
126
122
  }
127
- }
128
- };
129
- // Register event handler
130
- wsManager.on("data-event", handler);
131
- // Send the command
132
- sendCommand({
133
- config,
134
- sessionId,
135
- taskId,
136
- messageId,
137
- command,
138
- })
139
- .then(() => {
140
- })
141
- .catch((error) => {
142
- clearTimeout(timeout);
143
- wsManager.off("data-event", handler);
144
- reject(error);
123
+ };
124
+ // Register event handler
125
+ wsManager.on("data-event", handler);
126
+ // Send the command
127
+ sendCommand({
128
+ config,
129
+ sessionId,
130
+ taskId,
131
+ messageId,
132
+ command,
133
+ })
134
+ .then(() => {
135
+ })
136
+ .catch((error) => {
137
+ clearTimeout(timeout);
138
+ wsManager.off("data-event", handler);
139
+ reject(error);
140
+ });
145
141
  });
146
- });
147
- },
148
- };
142
+ },
143
+ };
144
+ }
@@ -1,4 +1,5 @@
1
+ import type { SessionContext } from "./session-manager.js";
1
2
  /**
2
3
  * XY delete collection tool - deletes data from user's XiaoYi collection.
3
4
  */
4
- export declare const xiaoyiDeleteCollectionTool: any;
5
+ export declare function createXiaoyiDeleteCollectionTool(ctx: SessionContext): any;