@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.
- package/dist/index.d.ts +6 -9
- package/dist/index.js +29 -23
- package/dist/src/bot.js +27 -3
- package/dist/src/channel.js +11 -23
- package/dist/src/cspl/call-api.js +14 -11
- package/dist/src/cspl/config.js +3 -3
- package/dist/src/cspl/constants.d.ts +2 -0
- package/dist/src/cspl/constants.js +12 -0
- package/dist/src/cspl/utils.js +4 -2
- package/dist/src/file-download.js +3 -6
- package/dist/src/file-upload.js +52 -5
- package/dist/src/login-token-handler.d.ts +8 -0
- package/dist/src/login-token-handler.js +60 -0
- package/dist/src/message-queue.d.ts +17 -0
- package/dist/src/message-queue.js +51 -0
- package/dist/src/monitor.js +54 -3
- package/dist/src/outbound.js +2 -7
- package/dist/src/provider.d.ts +2 -1
- package/dist/src/provider.js +486 -33
- package/dist/src/reply-dispatcher.js +6 -0
- package/dist/src/runtime.d.ts +3 -11
- package/dist/src/runtime.js +6 -18
- package/dist/src/self-evolution-handler.d.ts +7 -0
- package/dist/src/self-evolution-handler.js +140 -0
- 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/config.d.ts +4 -0
- package/dist/src/skill-retriever/config.js +23 -0
- package/dist/src/skill-retriever/hooks.d.ts +22 -0
- package/dist/src/skill-retriever/hooks.js +82 -0
- package/dist/src/skill-retriever/tool-search.d.ts +16 -0
- package/dist/src/skill-retriever/tool-search.js +172 -0
- package/dist/src/skill-retriever/types.d.ts +36 -0
- package/dist/src/skill-retriever/types.js +1 -0
- package/dist/src/task-manager.d.ts +4 -0
- package/dist/src/task-manager.js +6 -0
- package/dist/src/tools/call-device-tool.d.ts +5 -0
- package/dist/src/tools/call-device-tool.js +130 -0
- package/dist/src/tools/create-alarm-tool.js +5 -16
- package/dist/src/tools/delete-alarm-tool.js +1 -4
- package/dist/src/tools/device-tool-map.js +5 -4
- package/dist/src/tools/find-pc-devices-tool.d.ts +5 -0
- package/dist/src/tools/find-pc-devices-tool.js +98 -0
- package/dist/src/tools/get-alarm-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-alarm-tool-schema.js +11 -0
- package/dist/src/tools/get-calendar-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-calendar-tool-schema.js +9 -0
- package/dist/src/tools/get-collection-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-collection-tool-schema.js +10 -0
- package/dist/src/tools/get-contact-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-contact-tool-schema.js +11 -0
- package/dist/src/tools/get-device-file-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-device-file-tool-schema.js +10 -0
- package/dist/src/tools/get-email-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-email-tool-schema.js +9 -0
- package/dist/src/tools/get-note-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-note-tool-schema.js +10 -0
- package/dist/src/tools/get-photo-tool-schema.d.ts +16 -0
- package/dist/src/tools/get-photo-tool-schema.js +10 -0
- package/dist/src/tools/image-reading-tool.js +4 -7
- package/dist/src/tools/login-token-tool.d.ts +5 -0
- package/dist/src/tools/login-token-tool.js +136 -0
- package/dist/src/tools/modify-alarm-tool.js +10 -23
- package/dist/src/tools/query-app-message-tool.d.ts +4 -0
- package/dist/src/tools/query-app-message-tool.js +138 -0
- package/dist/src/tools/query-memory-data-tool.d.ts +4 -0
- package/dist/src/tools/query-memory-data-tool.js +154 -0
- package/dist/src/tools/query-todo-task-tool.d.ts +4 -0
- package/dist/src/tools/query-todo-task-tool.js +133 -0
- package/dist/src/tools/save-file-to-phone-tool.d.ts +5 -0
- package/dist/src/tools/save-file-to-phone-tool.js +166 -0
- package/dist/src/tools/save-media-to-gallery-tool.js +3 -7
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +1 -0
- package/dist/src/tools/save-self-evolution-skill-tool.js +412 -0
- package/dist/src/tools/schema-tool-factory.d.ts +27 -0
- package/dist/src/tools/schema-tool-factory.js +32 -0
- package/dist/src/tools/search-alarm-tool.js +6 -13
- package/dist/src/tools/search-calendar-tool.js +2 -0
- package/dist/src/tools/search-email-tool.d.ts +5 -0
- package/dist/src/tools/search-email-tool.js +137 -0
- package/dist/src/tools/search-file-tool.js +4 -4
- package/dist/src/tools/search-message-tool.js +1 -0
- package/dist/src/tools/search-photo-gallery-tool.js +2 -2
- package/dist/src/tools/send-email-tool.d.ts +4 -0
- package/dist/src/tools/send-email-tool.js +134 -0
- package/dist/src/tools/send-file-to-user-tool.js +3 -5
- package/dist/src/tools/session-manager.js +2 -0
- package/dist/src/tools/upload-file-tool.js +4 -4
- package/dist/src/tools/upload-photo-tool.js +2 -2
- package/dist/src/tools/xiaoyi-add-collection-tool.js +23 -4
- package/dist/src/tools/xiaoyi-collection-tool.js +2 -1
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +1 -1
- 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 +68 -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 +69 -0
- package/openclaw.plugin.json +21 -0
- 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
|
+
}
|
package/dist/src/monitor.js
CHANGED
|
@@ -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(() => {
|
package/dist/src/outbound.js
CHANGED
|
@@ -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
|
-
|
|
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,
|
package/dist/src/provider.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-
|
|
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;
|