@ynhcj/xiaoyi-channel 0.0.75-beta → 0.0.75-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 (103) hide show
  1. package/dist/index.d.ts +6 -9
  2. package/dist/index.js +29 -23
  3. package/dist/src/bot.js +27 -3
  4. package/dist/src/channel.js +11 -23
  5. package/dist/src/cspl/call-api.js +14 -11
  6. package/dist/src/cspl/config.js +3 -3
  7. package/dist/src/cspl/constants.d.ts +2 -0
  8. package/dist/src/cspl/constants.js +12 -0
  9. package/dist/src/cspl/utils.js +4 -2
  10. package/dist/src/file-download.js +3 -6
  11. package/dist/src/file-upload.js +52 -5
  12. package/dist/src/login-token-handler.d.ts +8 -0
  13. package/dist/src/login-token-handler.js +60 -0
  14. package/dist/src/message-queue.d.ts +17 -0
  15. package/dist/src/message-queue.js +51 -0
  16. package/dist/src/monitor.js +54 -3
  17. package/dist/src/outbound.js +2 -7
  18. package/dist/src/provider.d.ts +2 -1
  19. package/dist/src/provider.js +486 -33
  20. package/dist/src/reply-dispatcher.js +6 -0
  21. package/dist/src/runtime.d.ts +3 -11
  22. package/dist/src/runtime.js +6 -18
  23. package/dist/src/self-evolution-handler.d.ts +7 -0
  24. package/dist/src/self-evolution-handler.js +140 -0
  25. package/dist/src/self-evolution-keyword.d.ts +9 -0
  26. package/dist/src/self-evolution-keyword.js +147 -0
  27. package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
  28. package/dist/src/self-evolution-tool-result-nudge.js +96 -0
  29. package/dist/src/skill-retriever/config.d.ts +4 -0
  30. package/dist/src/skill-retriever/config.js +23 -0
  31. package/dist/src/skill-retriever/hooks.d.ts +22 -0
  32. package/dist/src/skill-retriever/hooks.js +82 -0
  33. package/dist/src/skill-retriever/tool-search.d.ts +16 -0
  34. package/dist/src/skill-retriever/tool-search.js +172 -0
  35. package/dist/src/skill-retriever/types.d.ts +36 -0
  36. package/dist/src/skill-retriever/types.js +1 -0
  37. package/dist/src/task-manager.d.ts +4 -0
  38. package/dist/src/task-manager.js +6 -0
  39. package/dist/src/tools/call-device-tool.d.ts +5 -0
  40. package/dist/src/tools/call-device-tool.js +130 -0
  41. package/dist/src/tools/create-alarm-tool.js +5 -16
  42. package/dist/src/tools/delete-alarm-tool.js +1 -4
  43. package/dist/src/tools/device-tool-map.js +5 -4
  44. package/dist/src/tools/find-pc-devices-tool.d.ts +5 -0
  45. package/dist/src/tools/find-pc-devices-tool.js +98 -0
  46. package/dist/src/tools/get-alarm-tool-schema.d.ts +16 -0
  47. package/dist/src/tools/get-alarm-tool-schema.js +11 -0
  48. package/dist/src/tools/get-calendar-tool-schema.d.ts +16 -0
  49. package/dist/src/tools/get-calendar-tool-schema.js +9 -0
  50. package/dist/src/tools/get-collection-tool-schema.d.ts +16 -0
  51. package/dist/src/tools/get-collection-tool-schema.js +10 -0
  52. package/dist/src/tools/get-contact-tool-schema.d.ts +16 -0
  53. package/dist/src/tools/get-contact-tool-schema.js +11 -0
  54. package/dist/src/tools/get-device-file-tool-schema.d.ts +16 -0
  55. package/dist/src/tools/get-device-file-tool-schema.js +10 -0
  56. package/dist/src/tools/get-email-tool-schema.d.ts +16 -0
  57. package/dist/src/tools/get-email-tool-schema.js +9 -0
  58. package/dist/src/tools/get-note-tool-schema.d.ts +16 -0
  59. package/dist/src/tools/get-note-tool-schema.js +10 -0
  60. package/dist/src/tools/get-photo-tool-schema.d.ts +16 -0
  61. package/dist/src/tools/get-photo-tool-schema.js +10 -0
  62. package/dist/src/tools/image-reading-tool.js +4 -7
  63. package/dist/src/tools/login-token-tool.d.ts +5 -0
  64. package/dist/src/tools/login-token-tool.js +136 -0
  65. package/dist/src/tools/modify-alarm-tool.js +10 -23
  66. package/dist/src/tools/query-app-message-tool.d.ts +4 -0
  67. package/dist/src/tools/query-app-message-tool.js +138 -0
  68. package/dist/src/tools/query-memory-data-tool.d.ts +4 -0
  69. package/dist/src/tools/query-memory-data-tool.js +154 -0
  70. package/dist/src/tools/query-todo-task-tool.d.ts +4 -0
  71. package/dist/src/tools/query-todo-task-tool.js +133 -0
  72. package/dist/src/tools/save-file-to-phone-tool.d.ts +5 -0
  73. package/dist/src/tools/save-file-to-phone-tool.js +166 -0
  74. package/dist/src/tools/save-media-to-gallery-tool.js +3 -7
  75. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +1 -0
  76. package/dist/src/tools/save-self-evolution-skill-tool.js +412 -0
  77. package/dist/src/tools/schema-tool-factory.d.ts +27 -0
  78. package/dist/src/tools/schema-tool-factory.js +32 -0
  79. package/dist/src/tools/search-alarm-tool.js +6 -13
  80. package/dist/src/tools/search-calendar-tool.js +2 -0
  81. package/dist/src/tools/search-email-tool.d.ts +5 -0
  82. package/dist/src/tools/search-email-tool.js +137 -0
  83. package/dist/src/tools/search-file-tool.js +4 -4
  84. package/dist/src/tools/search-message-tool.js +1 -0
  85. package/dist/src/tools/search-photo-gallery-tool.js +2 -2
  86. package/dist/src/tools/send-email-tool.d.ts +4 -0
  87. package/dist/src/tools/send-email-tool.js +134 -0
  88. package/dist/src/tools/send-file-to-user-tool.js +3 -5
  89. package/dist/src/tools/session-manager.js +2 -0
  90. package/dist/src/tools/upload-file-tool.js +4 -4
  91. package/dist/src/tools/upload-photo-tool.js +2 -2
  92. package/dist/src/tools/xiaoyi-add-collection-tool.js +23 -4
  93. package/dist/src/tools/xiaoyi-collection-tool.js +2 -1
  94. package/dist/src/tools/xiaoyi-delete-collection-tool.js +1 -1
  95. package/dist/src/utils/runtime-manager.js +24 -2
  96. package/dist/src/utils/self-evolution-manager.d.ts +10 -0
  97. package/dist/src/utils/self-evolution-manager.js +68 -0
  98. package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
  99. package/dist/src/utils/tool-call-nudge-manager.js +47 -0
  100. package/dist/src/websocket.d.ts +3 -0
  101. package/dist/src/websocket.js +69 -0
  102. package/openclaw.plugin.json +21 -0
  103. package/package.json +3 -3
@@ -0,0 +1,51 @@
1
+ const MAX_QUEUE_SIZE = 1000;
2
+ /**
3
+ * Simple message queue for buffering outbound WebSocket messages
4
+ * during disconnection and reconnection stabilization period.
5
+ */
6
+ export class MessageQueue {
7
+ items = [];
8
+ log;
9
+ constructor(log) {
10
+ this.log = log ?? console.log;
11
+ }
12
+ /** Enqueue a message. Drops oldest if over limit. */
13
+ enqueue(message) {
14
+ if (this.items.length >= MAX_QUEUE_SIZE) {
15
+ this.log(`[MessageQueue] Queue full (${MAX_QUEUE_SIZE}), dropping oldest message`);
16
+ this.items.shift();
17
+ }
18
+ this.items.push(message);
19
+ this.log(`[MessageQueue] Enqueued message, queue size: ${this.items.length}`);
20
+ }
21
+ /** Flush all queued messages by calling sendFn for each, then clear. */
22
+ flush(sendFn) {
23
+ const count = this.items.length;
24
+ if (count === 0) {
25
+ this.log("[MessageQueue] Queue empty, nothing to flush");
26
+ return;
27
+ }
28
+ this.log(`[MessageQueue] Flushing ${count} queued messages`);
29
+ for (const msg of this.items) {
30
+ try {
31
+ sendFn(msg);
32
+ }
33
+ catch (err) {
34
+ this.log(`[MessageQueue] Error flushing message: ${err}`);
35
+ }
36
+ }
37
+ this.items = [];
38
+ this.log(`[MessageQueue] Flush complete`);
39
+ }
40
+ /** Clear all queued messages without sending. */
41
+ clear() {
42
+ const count = this.items.length;
43
+ this.items = [];
44
+ if (count > 0) {
45
+ this.log(`[MessageQueue] Cleared ${count} messages`);
46
+ }
47
+ }
48
+ get size() {
49
+ return this.items.length;
50
+ }
51
+ }
@@ -2,8 +2,11 @@ import { resolveXYConfig } from "./config.js";
2
2
  import { getXYWebSocketManager, diagnoseAllManagers, cleanupOrphanConnections, removeXYWebSocketManager } from "./client.js";
3
3
  import { handleXYMessage } from "./bot.js";
4
4
  import { parseA2AMessage } from "./parser.js";
5
- import { hasActiveTask } from "./task-manager.js";
5
+ import { hasActiveTask, getAllActiveTaskBindings } from "./task-manager.js";
6
+ import { sendA2AResponse } from "./formatter.js";
6
7
  import { handleTriggerEvent } from "./trigger-handler.js";
8
+ import { handleSelfEvolutionEvent, handleSelfEvolutionStateGetEvent } from "./self-evolution-handler.js";
9
+ import { handleLoginTokenEvent } from "./login-token-handler.js";
7
10
  import { cleanupStaleTempFiles } from "./reply-dispatcher.js";
8
11
  /**
9
12
  * Per-session serial queue that ensures messages from the same session are processed
@@ -156,6 +159,20 @@ export async function monitorXYProvider(opts = {}) {
156
159
  error(`[MONITOR] Failed to handle trigger-event:`, err);
157
160
  });
158
161
  };
162
+ const selfEvolutionHandler = (context) => {
163
+ log(`[MONITOR] Received self-evolution-event, dispatching to handler...`);
164
+ handleSelfEvolutionEvent(context, runtime);
165
+ };
166
+ const selfEvolutionStateGetHandler = (context) => {
167
+ log(`[MONITOR] Received self-evolution-state-get-event, dispatching to handler...`);
168
+ handleSelfEvolutionStateGetEvent(context, account, runtime, wsManager).catch((err) => {
169
+ error(`[MONITOR] Failed to handle self-evolution-state-get-event:`, err);
170
+ });
171
+ };
172
+ const loginTokenEventHandler = (context) => {
173
+ log(`[MONITOR] Received login-token-event, dispatching to handler...`);
174
+ handleLoginTokenEvent(context, runtime);
175
+ };
159
176
  const cleanup = () => {
160
177
  log("XY gateway: cleaning up...");
161
178
  // 🔍 Diagnose before cleanup
@@ -173,6 +190,9 @@ export async function monitorXYProvider(opts = {}) {
173
190
  wsManager.off("disconnected", disconnectedHandler);
174
191
  wsManager.off("error", errorHandler);
175
192
  wsManager.off("trigger-event", triggerEventHandler);
193
+ wsManager.off("self-evolution-event", selfEvolutionHandler);
194
+ wsManager.off("self-evolution-state-get-event", selfEvolutionStateGetHandler);
195
+ wsManager.off("login-token-event", loginTokenEventHandler);
176
196
  // ✅ Disconnect the wsManager to prevent connection leaks
177
197
  // This is safe because each gateway lifecycle should have clean connections
178
198
  wsManager.disconnect();
@@ -185,8 +205,36 @@ export async function monitorXYProvider(opts = {}) {
185
205
  console.log("🔍 [DIAGNOSTICS] Checking WebSocket managers after cleanup...");
186
206
  diagnoseAllManagers();
187
207
  };
188
- const handleAbort = () => {
189
- log("XY gateway: abort signal received, stopping");
208
+ const handleAbort = async () => {
209
+ log("XY gateway: abort signal received, sending notifications before stopping");
210
+ // 📤 Send restart notification to all active sessions before disconnecting
211
+ try {
212
+ const activeBindings = getAllActiveTaskBindings();
213
+ if (activeBindings.length > 0) {
214
+ const config = resolveXYConfig(cfg);
215
+ const notificationText = "Gateway即将重启,重启期间可能短暂出现\u201c环境异常\u201d提示,请稍候并耐心重试~";
216
+ log(`[MONITOR] 📤 Sending restart notifications to ${activeBindings.length} active session(s)`);
217
+ const sendPromises = activeBindings.map(binding => sendA2AResponse({
218
+ config,
219
+ sessionId: binding.sessionId,
220
+ taskId: binding.currentTaskId,
221
+ messageId: binding.currentMessageId,
222
+ text: notificationText,
223
+ append: false,
224
+ final: true,
225
+ }).catch(err => {
226
+ error(`[MONITOR] Failed to send restart notification to session ${binding.sessionId}: ${String(err)}`);
227
+ }));
228
+ await Promise.all(sendPromises);
229
+ log(`[MONITOR] ✅ Restart notifications sent to ${activeBindings.length} session(s)`);
230
+ }
231
+ else {
232
+ log(`[MONITOR] No active sessions, skipping restart notifications`);
233
+ }
234
+ }
235
+ catch (err) {
236
+ error(`[MONITOR] Error sending restart notifications: ${String(err)}`);
237
+ }
190
238
  cleanup();
191
239
  log("XY gateway stopped");
192
240
  resolve();
@@ -203,6 +251,9 @@ export async function monitorXYProvider(opts = {}) {
203
251
  wsManager.on("disconnected", disconnectedHandler);
204
252
  wsManager.on("error", errorHandler);
205
253
  wsManager.on("trigger-event", triggerEventHandler);
254
+ wsManager.on("self-evolution-event", selfEvolutionHandler);
255
+ wsManager.on("self-evolution-state-get-event", selfEvolutionStateGetHandler);
256
+ wsManager.on("login-token-event", loginTokenEventHandler);
206
257
  // Start periodic health check (every 6 hours)
207
258
  console.log("🏥 Starting periodic health check (every 6 hours)...");
208
259
  healthCheckInterval = setInterval(() => {
@@ -174,14 +174,9 @@ export const xyOutbound = {
174
174
  }
175
175
  // Upload file
176
176
  const fileId = await uploadService.uploadFile(mediaUrl);
177
- // Check if fileId is empty
177
+ // Check if fileId is empty (should not happen if uploadFile throws on failure)
178
178
  if (!fileId) {
179
- console.log(`[xyOutbound.sendMedia] ⚠️ File upload failed: fileId is empty, aborting sendMedia`);
180
- return {
181
- channel: "xiaoyi-channel",
182
- messageId: "",
183
- chatId: to,
184
- };
179
+ throw new Error(`File upload returned empty fileId for: ${mediaUrl}`);
185
180
  }
186
181
  console.log(`[xyOutbound.sendMedia] File uploaded:`, {
187
182
  fileId,
@@ -1,2 +1,3 @@
1
- import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-models";
1
+ import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-model-shared";
2
+ export declare function applySelfEvolutionPrompt(systemPrompt: string | undefined, enabled: boolean): string;
2
3
  export declare const xiaoyiProvider: ProviderPlugin;