@ynhcj/xiaoyi 2.5.5 → 2.5.7
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/auth.d.ts +1 -1
- package/dist/channel.d.ts +116 -14
- package/dist/channel.js +199 -665
- package/dist/config-schema.d.ts +8 -8
- package/dist/config-schema.js +5 -5
- package/dist/file-download.d.ts +17 -0
- package/dist/file-download.js +69 -0
- package/dist/heartbeat.d.ts +39 -0
- package/dist/heartbeat.js +102 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.js +7 -11
- package/dist/push.d.ts +28 -0
- package/dist/push.js +135 -0
- package/dist/runtime.d.ts +48 -2
- package/dist/runtime.js +117 -3
- package/dist/types.d.ts +95 -1
- package/dist/websocket.d.ts +49 -1
- package/dist/websocket.js +279 -20
- package/dist/xy-bot.d.ts +19 -0
- package/dist/xy-bot.js +277 -0
- package/dist/xy-client.d.ts +26 -0
- package/dist/xy-client.js +78 -0
- package/dist/xy-config.d.ts +18 -0
- package/dist/xy-config.js +37 -0
- package/dist/xy-formatter.d.ts +94 -0
- package/dist/xy-formatter.js +303 -0
- package/dist/xy-monitor.d.ts +17 -0
- package/dist/xy-monitor.js +187 -0
- package/dist/xy-parser.d.ts +49 -0
- package/dist/xy-parser.js +109 -0
- package/dist/xy-reply-dispatcher.d.ts +17 -0
- package/dist/xy-reply-dispatcher.js +308 -0
- package/dist/xy-tools/session-manager.d.ts +29 -0
- package/dist/xy-tools/session-manager.js +80 -0
- package/dist/xy-utils/config-manager.d.ts +26 -0
- package/dist/xy-utils/config-manager.js +61 -0
- package/dist/xy-utils/crypto.d.ts +8 -0
- package/dist/xy-utils/crypto.js +21 -0
- package/dist/xy-utils/logger.d.ts +6 -0
- package/dist/xy-utils/logger.js +37 -0
- package/dist/xy-utils/session.d.ts +34 -0
- package/dist/xy-utils/session.js +55 -0
- package/package.json +32 -16
package/dist/xy-bot.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleXYMessage = handleXYMessage;
|
|
4
|
+
const runtime_js_1 = require("./runtime.js");
|
|
5
|
+
const xy_reply_dispatcher_js_1 = require("./xy-reply-dispatcher.js");
|
|
6
|
+
const xy_parser_js_1 = require("./xy-parser.js");
|
|
7
|
+
const file_download_js_1 = require("./file-download.js");
|
|
8
|
+
const xy_config_js_1 = require("./xy-config.js");
|
|
9
|
+
const xy_formatter_js_1 = require("./xy-formatter.js");
|
|
10
|
+
const session_manager_js_1 = require("./xy-tools/session-manager.js");
|
|
11
|
+
const config_manager_js_1 = require("./xy-utils/config-manager.js");
|
|
12
|
+
/**
|
|
13
|
+
* Handle an incoming A2A message.
|
|
14
|
+
* This is the main entry point for message processing.
|
|
15
|
+
* Runtime is expected to be validated before calling this function.
|
|
16
|
+
*/
|
|
17
|
+
async function handleXYMessage(params) {
|
|
18
|
+
const { cfg, runtime, message, accountId } = params;
|
|
19
|
+
const log = runtime?.log ?? console.log;
|
|
20
|
+
const error = runtime?.error ?? console.error;
|
|
21
|
+
// Get OpenClaw PluginRuntime (not XiaoYiRuntime)
|
|
22
|
+
const xiaoYiRuntime = (0, runtime_js_1.getXiaoYiRuntime)();
|
|
23
|
+
const core = xiaoYiRuntime.getPluginRuntime();
|
|
24
|
+
try {
|
|
25
|
+
// Check for special messages BEFORE parsing (these have different param structures)
|
|
26
|
+
const messageMethod = message.method;
|
|
27
|
+
log(`[BOT-ENTRY] <<<<<<< Received message with method: ${messageMethod}, id: ${message.id} >>>>>>>`);
|
|
28
|
+
log(`[BOT-ENTRY] Stack trace for debugging:`, new Error().stack?.split('\n').slice(1, 4).join('\n'));
|
|
29
|
+
// Handle clearContext messages (params only has sessionId)
|
|
30
|
+
if (messageMethod === "clearContext" || messageMethod === "clear_context") {
|
|
31
|
+
const sessionId = message.params?.sessionId;
|
|
32
|
+
if (!sessionId) {
|
|
33
|
+
throw new Error("clearContext request missing sessionId in params");
|
|
34
|
+
}
|
|
35
|
+
log(`Clear context request for session ${sessionId}`);
|
|
36
|
+
const config = (0, xy_config_js_1.resolveXYConfig)(cfg);
|
|
37
|
+
await (0, xy_formatter_js_1.sendClearContextResponse)({
|
|
38
|
+
config,
|
|
39
|
+
sessionId,
|
|
40
|
+
messageId: message.id,
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Handle tasks/cancel messages
|
|
45
|
+
if (messageMethod === "tasks/cancel" || messageMethod === "tasks_cancel") {
|
|
46
|
+
const sessionId = message.params?.sessionId;
|
|
47
|
+
const taskId = message.params?.id || message.id;
|
|
48
|
+
if (!sessionId) {
|
|
49
|
+
throw new Error("tasks/cancel request missing sessionId in params");
|
|
50
|
+
}
|
|
51
|
+
log(`Tasks cancel request for session ${sessionId}, task ${taskId}`);
|
|
52
|
+
const config = (0, xy_config_js_1.resolveXYConfig)(cfg);
|
|
53
|
+
await (0, xy_formatter_js_1.sendTasksCancelResponse)({
|
|
54
|
+
config,
|
|
55
|
+
sessionId,
|
|
56
|
+
taskId,
|
|
57
|
+
messageId: message.id,
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Parse the A2A message (for regular messages)
|
|
62
|
+
const parsed = (0, xy_parser_js_1.parseA2AMessage)(message);
|
|
63
|
+
// Extract and update push_id if present
|
|
64
|
+
const pushId = (0, xy_parser_js_1.extractPushId)(parsed.parts);
|
|
65
|
+
if (pushId) {
|
|
66
|
+
log(`[BOT] 📌 Extracted push_id from user message`);
|
|
67
|
+
log(`[BOT] - Session ID: ${parsed.sessionId}`);
|
|
68
|
+
log(`[BOT] - Push ID preview: ${pushId.substring(0, 20)}...`);
|
|
69
|
+
log(`[BOT] - Full push_id: ${pushId}`);
|
|
70
|
+
config_manager_js_1.configManager.updatePushId(parsed.sessionId, pushId);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
log(`[BOT] ℹ️ No push_id found in message, will use config default`);
|
|
74
|
+
}
|
|
75
|
+
// Resolve configuration (needed for status updates)
|
|
76
|
+
const config = (0, xy_config_js_1.resolveXYConfig)(cfg);
|
|
77
|
+
// ✅ Resolve agent route (following feishu pattern)
|
|
78
|
+
// accountId is "default" for XY (single account mode)
|
|
79
|
+
// Use sessionId as peer.id to ensure all messages in the same session share context
|
|
80
|
+
let route = core.channel.routing.resolveAgentRoute({
|
|
81
|
+
cfg,
|
|
82
|
+
channel: "xiaoyi-channel",
|
|
83
|
+
accountId, // "default"
|
|
84
|
+
peer: {
|
|
85
|
+
kind: "direct",
|
|
86
|
+
id: parsed.sessionId, // ✅ Use sessionId to share context within the same conversation session
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
log(`xy: resolved route accountId=${route.accountId}, sessionKey=${route.sessionKey}`);
|
|
90
|
+
// Register session context for tools
|
|
91
|
+
log(`[BOT] 📝 About to register session for tools...`);
|
|
92
|
+
log(`[BOT] - sessionKey: ${route.sessionKey}`);
|
|
93
|
+
log(`[BOT] - sessionId: ${parsed.sessionId}`);
|
|
94
|
+
log(`[BOT] - taskId: ${parsed.taskId}`);
|
|
95
|
+
(0, session_manager_js_1.registerSession)(route.sessionKey, {
|
|
96
|
+
config,
|
|
97
|
+
sessionId: parsed.sessionId,
|
|
98
|
+
taskId: parsed.taskId,
|
|
99
|
+
messageId: parsed.messageId,
|
|
100
|
+
agentId: route.accountId,
|
|
101
|
+
});
|
|
102
|
+
log(`[BOT] ✅ Session registered for tools`);
|
|
103
|
+
// Send initial status update immediately after parsing message
|
|
104
|
+
log(`[STATUS] Sending initial status update for session ${parsed.sessionId}`);
|
|
105
|
+
void (0, xy_formatter_js_1.sendStatusUpdate)({
|
|
106
|
+
config,
|
|
107
|
+
sessionId: parsed.sessionId,
|
|
108
|
+
taskId: parsed.taskId,
|
|
109
|
+
messageId: parsed.messageId,
|
|
110
|
+
text: "任务正在处理中,请稍后~",
|
|
111
|
+
state: "working",
|
|
112
|
+
}).catch((err) => {
|
|
113
|
+
error(`Failed to send initial status update:`, err);
|
|
114
|
+
});
|
|
115
|
+
// Extract text and files from parts
|
|
116
|
+
const text = (0, xy_parser_js_1.extractTextFromParts)(parsed.parts);
|
|
117
|
+
const fileParts = (0, xy_parser_js_1.extractFileParts)(parsed.parts);
|
|
118
|
+
// Download files if present (using core's media download)
|
|
119
|
+
const mediaList = await (0, file_download_js_1.downloadFilesFromParts)(fileParts);
|
|
120
|
+
// Build media payload for inbound context (following feishu pattern)
|
|
121
|
+
const mediaPayload = buildXYMediaPayload(mediaList);
|
|
122
|
+
// Resolve envelope format options (following feishu pattern)
|
|
123
|
+
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(cfg);
|
|
124
|
+
// Build message body with speaker prefix (following feishu pattern)
|
|
125
|
+
let messageBody = text || "";
|
|
126
|
+
// Add speaker prefix for clarity
|
|
127
|
+
const speaker = parsed.sessionId;
|
|
128
|
+
messageBody = `${speaker}: ${messageBody}`;
|
|
129
|
+
// Format agent envelope (following feishu pattern)
|
|
130
|
+
const body = core.channel.reply.formatAgentEnvelope({
|
|
131
|
+
channel: "xiaoyi-channel",
|
|
132
|
+
from: speaker,
|
|
133
|
+
timestamp: new Date(),
|
|
134
|
+
envelope: envelopeOptions,
|
|
135
|
+
body: messageBody,
|
|
136
|
+
});
|
|
137
|
+
// ✅ Finalize inbound context (following feishu pattern)
|
|
138
|
+
// Use route.accountId and route.sessionKey instead of parsed fields
|
|
139
|
+
const ctxPayload = core.channel.reply.finalizeInboundContext({
|
|
140
|
+
Body: body,
|
|
141
|
+
RawBody: text || "",
|
|
142
|
+
CommandBody: text || "",
|
|
143
|
+
From: parsed.sessionId,
|
|
144
|
+
To: parsed.sessionId, // ✅ Simplified: use sessionId as target (context is managed by SessionKey)
|
|
145
|
+
SessionKey: route.sessionKey, // ✅ Use route.sessionKey
|
|
146
|
+
AccountId: route.accountId, // ✅ Use route.accountId ("default")
|
|
147
|
+
ChatType: "direct",
|
|
148
|
+
GroupSubject: undefined,
|
|
149
|
+
SenderName: parsed.sessionId,
|
|
150
|
+
SenderId: parsed.sessionId,
|
|
151
|
+
Provider: "xiaoyi-channel",
|
|
152
|
+
Surface: "xiaoyi-channel",
|
|
153
|
+
MessageSid: parsed.messageId,
|
|
154
|
+
Timestamp: Date.now(),
|
|
155
|
+
WasMentioned: false,
|
|
156
|
+
CommandAuthorized: true,
|
|
157
|
+
OriginatingChannel: "xiaoyi-channel",
|
|
158
|
+
OriginatingTo: parsed.sessionId, // Original message target
|
|
159
|
+
ReplyToBody: undefined, // A2A protocol doesn't support reply/quote
|
|
160
|
+
...mediaPayload,
|
|
161
|
+
});
|
|
162
|
+
// Send initial status update immediately after parsing message
|
|
163
|
+
log(`[STATUS] Sending initial status update for session ${parsed.sessionId}`);
|
|
164
|
+
void (0, xy_formatter_js_1.sendStatusUpdate)({
|
|
165
|
+
config,
|
|
166
|
+
sessionId: parsed.sessionId,
|
|
167
|
+
taskId: parsed.taskId,
|
|
168
|
+
messageId: parsed.messageId,
|
|
169
|
+
text: "任务正在处理中,请稍后~",
|
|
170
|
+
state: "working",
|
|
171
|
+
}).catch((err) => {
|
|
172
|
+
error(`Failed to send initial status update:`, err);
|
|
173
|
+
});
|
|
174
|
+
// Create reply dispatcher (following feishu pattern)
|
|
175
|
+
log(`[BOT-DISPATCHER] 🎯 Creating reply dispatcher for session=${parsed.sessionId}, taskId=${parsed.taskId}, messageId=${parsed.messageId}`);
|
|
176
|
+
const { dispatcher, replyOptions, markDispatchIdle, startStatusInterval } = (0, xy_reply_dispatcher_js_1.createXYReplyDispatcher)({
|
|
177
|
+
cfg,
|
|
178
|
+
runtime,
|
|
179
|
+
sessionId: parsed.sessionId,
|
|
180
|
+
taskId: parsed.taskId,
|
|
181
|
+
messageId: parsed.messageId,
|
|
182
|
+
accountId: route.accountId, // ✅ Use route.accountId
|
|
183
|
+
});
|
|
184
|
+
log(`[BOT-DISPATCHER] ✅ Reply dispatcher created successfully`);
|
|
185
|
+
// Start status update interval (will send updates every 60 seconds)
|
|
186
|
+
// Interval will be automatically stopped when onIdle/onCleanup is triggered
|
|
187
|
+
startStatusInterval();
|
|
188
|
+
log(`xy: dispatching to agent (session=${parsed.sessionId})`);
|
|
189
|
+
// Dispatch to OpenClaw core using correct API (following feishu pattern)
|
|
190
|
+
log(`[BOT] 🚀 Starting dispatcher with session: ${route.sessionKey}`);
|
|
191
|
+
await core.channel.reply.withReplyDispatcher({
|
|
192
|
+
dispatcher,
|
|
193
|
+
onSettled: () => {
|
|
194
|
+
log(`[BOT] 🏁 onSettled called for session: ${route.sessionKey}`);
|
|
195
|
+
log(`[BOT] - About to unregister session...`);
|
|
196
|
+
markDispatchIdle();
|
|
197
|
+
// Unregister session context when done
|
|
198
|
+
(0, session_manager_js_1.unregisterSession)(route.sessionKey);
|
|
199
|
+
log(`[BOT] ✅ Session unregistered in onSettled`);
|
|
200
|
+
},
|
|
201
|
+
run: () => core.channel.reply.dispatchReplyFromConfig({
|
|
202
|
+
ctx: ctxPayload,
|
|
203
|
+
cfg,
|
|
204
|
+
dispatcher,
|
|
205
|
+
replyOptions,
|
|
206
|
+
}),
|
|
207
|
+
});
|
|
208
|
+
log(`[BOT] ✅ Dispatcher completed for session: ${parsed.sessionId}`);
|
|
209
|
+
log(`xy: dispatch complete (session=${parsed.sessionId})`);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
// ✅ Only log error, don't re-throw to prevent gateway restart
|
|
213
|
+
error("Failed to handle XY message:", err);
|
|
214
|
+
runtime.error?.(`xy: Failed to handle message: ${String(err)}`);
|
|
215
|
+
log(`[BOT] ❌ Error occurred, attempting cleanup...`);
|
|
216
|
+
// Try to unregister session on error (if route was established)
|
|
217
|
+
try {
|
|
218
|
+
const xiaoYiRuntime = (0, runtime_js_1.getXiaoYiRuntime)();
|
|
219
|
+
const core = xiaoYiRuntime.getPluginRuntime();
|
|
220
|
+
const params = message.params;
|
|
221
|
+
const sessionId = params?.sessionId;
|
|
222
|
+
if (sessionId) {
|
|
223
|
+
log(`[BOT] 🧹 Cleaning up session after error: ${sessionId}`);
|
|
224
|
+
const route = core.channel.routing.resolveAgentRoute({
|
|
225
|
+
cfg,
|
|
226
|
+
channel: "xiaoyi-channel",
|
|
227
|
+
accountId,
|
|
228
|
+
peer: {
|
|
229
|
+
kind: "direct",
|
|
230
|
+
id: sessionId, // ✅ Use sessionId for cleanup consistency
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
log(`[BOT] - Unregistering session: ${route.sessionKey}`);
|
|
234
|
+
(0, session_manager_js_1.unregisterSession)(route.sessionKey);
|
|
235
|
+
log(`[BOT] ✅ Session unregistered after error`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch (cleanupErr) {
|
|
239
|
+
log(`[BOT] ⚠️ Cleanup failed:`, cleanupErr);
|
|
240
|
+
// Ignore cleanup errors
|
|
241
|
+
}
|
|
242
|
+
// ❌ Don't re-throw: message processing error should not affect gateway stability
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Build media payload for inbound context.
|
|
247
|
+
* Following feishu pattern: buildFeishuMediaPayload().
|
|
248
|
+
*/
|
|
249
|
+
function buildXYMediaPayload(mediaList) {
|
|
250
|
+
const first = mediaList[0];
|
|
251
|
+
const mediaPaths = mediaList.map((media) => media.path);
|
|
252
|
+
const mediaTypes = mediaList.map((media) => media.mimeType).filter(Boolean);
|
|
253
|
+
return {
|
|
254
|
+
MediaPath: first?.path,
|
|
255
|
+
MediaType: first?.mimeType,
|
|
256
|
+
MediaUrl: first?.path,
|
|
257
|
+
MediaPaths: mediaPaths.length > 0 ? mediaPaths : undefined,
|
|
258
|
+
MediaUrls: mediaPaths.length > 0 ? mediaPaths : undefined,
|
|
259
|
+
MediaTypes: mediaTypes.length > 0 ? mediaTypes : undefined,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Infer OpenClaw media type from file type string.
|
|
264
|
+
*/
|
|
265
|
+
function inferMediaType(fileType) {
|
|
266
|
+
const lower = fileType.toLowerCase();
|
|
267
|
+
if (lower.includes("image") || /\.(jpg|jpeg|png|gif|bmp|webp)$/i.test(lower)) {
|
|
268
|
+
return "image";
|
|
269
|
+
}
|
|
270
|
+
if (lower.includes("video") || /\.(mp4|avi|mov|mkv|webm)$/i.test(lower)) {
|
|
271
|
+
return "video";
|
|
272
|
+
}
|
|
273
|
+
if (lower.includes("audio") || /\.(mp3|wav|ogg|m4a)$/i.test(lower)) {
|
|
274
|
+
return "audio";
|
|
275
|
+
}
|
|
276
|
+
return "file";
|
|
277
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { XiaoYiWebSocketManager } from "./websocket.js";
|
|
2
|
+
import type { XiaoYiChannelConfig } from "./types.js";
|
|
3
|
+
import type { RuntimeEnv } from "openclaw/dist/plugin-sdk/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Set the runtime for logging in client module.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setClientRuntime(rt: RuntimeEnv | undefined): void;
|
|
8
|
+
/**
|
|
9
|
+
* Get or create a WebSocket manager for the given configuration.
|
|
10
|
+
* Reuses existing managers if config matches.
|
|
11
|
+
* Adapted for xiaoyi - uses aksk instead of apiKey/uid
|
|
12
|
+
*/
|
|
13
|
+
export declare function getXYWebSocketManager(config: XiaoYiChannelConfig): XiaoYiWebSocketManager;
|
|
14
|
+
/**
|
|
15
|
+
* Remove a specific WebSocket manager from cache.
|
|
16
|
+
* Disconnects the manager and removes it from the cache.
|
|
17
|
+
*/
|
|
18
|
+
export declare function removeXYWebSocketManager(config: XiaoYiChannelConfig): void;
|
|
19
|
+
/**
|
|
20
|
+
* Clear all cached WebSocket managers.
|
|
21
|
+
*/
|
|
22
|
+
export declare function clearXYWebSocketManagers(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Get the number of cached managers.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getCachedManagerCount(): number;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setClientRuntime = setClientRuntime;
|
|
4
|
+
exports.getXYWebSocketManager = getXYWebSocketManager;
|
|
5
|
+
exports.removeXYWebSocketManager = removeXYWebSocketManager;
|
|
6
|
+
exports.clearXYWebSocketManagers = clearXYWebSocketManagers;
|
|
7
|
+
exports.getCachedManagerCount = getCachedManagerCount;
|
|
8
|
+
// WebSocket client cache management
|
|
9
|
+
// Adapted for xiaoyi - uses xiaoyi's WebSocket manager with aksk auth
|
|
10
|
+
const websocket_js_1 = require("./websocket.js");
|
|
11
|
+
// Runtime reference for logging
|
|
12
|
+
let runtime;
|
|
13
|
+
/**
|
|
14
|
+
* Set the runtime for logging in client module.
|
|
15
|
+
*/
|
|
16
|
+
function setClientRuntime(rt) {
|
|
17
|
+
runtime = rt;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Global cache for WebSocket managers.
|
|
21
|
+
* Key format: `${ak}-${agentId}` (using xiaoyi's aksk auth)
|
|
22
|
+
*/
|
|
23
|
+
const wsManagerCache = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Get or create a WebSocket manager for the given configuration.
|
|
26
|
+
* Reuses existing managers if config matches.
|
|
27
|
+
* Adapted for xiaoyi - uses aksk instead of apiKey/uid
|
|
28
|
+
*/
|
|
29
|
+
function getXYWebSocketManager(config) {
|
|
30
|
+
const cacheKey = `${config.ak}-${config.agentId}`;
|
|
31
|
+
let cached = wsManagerCache.get(cacheKey);
|
|
32
|
+
if (cached) {
|
|
33
|
+
const log = runtime?.log ?? console.log;
|
|
34
|
+
log(`[WS-MANAGER-CACHE] ✅ Reusing cached WebSocket manager: ${cacheKey}, total managers: ${wsManagerCache.size}`);
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
37
|
+
// Create new manager with xiaoyi's config (aksk auth)
|
|
38
|
+
const log = runtime?.log ?? console.log;
|
|
39
|
+
log(`[WS-MANAGER-CACHE] 🆕 Creating new WebSocket manager: ${cacheKey}, total managers before: ${wsManagerCache.size}`);
|
|
40
|
+
cached = new websocket_js_1.XiaoYiWebSocketManager(config);
|
|
41
|
+
wsManagerCache.set(cacheKey, cached);
|
|
42
|
+
log(`[WS-MANAGER-CACHE] 📊 Total managers after creation: ${wsManagerCache.size}`);
|
|
43
|
+
return cached;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Remove a specific WebSocket manager from cache.
|
|
47
|
+
* Disconnects the manager and removes it from the cache.
|
|
48
|
+
*/
|
|
49
|
+
function removeXYWebSocketManager(config) {
|
|
50
|
+
const cacheKey = `${config.ak}-${config.agentId}`;
|
|
51
|
+
const manager = wsManagerCache.get(cacheKey);
|
|
52
|
+
if (manager) {
|
|
53
|
+
console.log(`🗑️ [WS-MANAGER-CACHE] Removing manager from cache: ${cacheKey}`);
|
|
54
|
+
manager.disconnect();
|
|
55
|
+
wsManagerCache.delete(cacheKey);
|
|
56
|
+
console.log(`🗑️ [WS-MANAGER-CACHE] Manager removed, remaining managers: ${wsManagerCache.size}`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log(`⚠️ [WS-MANAGER-CACHE] Manager not found in cache: ${cacheKey}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Clear all cached WebSocket managers.
|
|
64
|
+
*/
|
|
65
|
+
function clearXYWebSocketManagers() {
|
|
66
|
+
const log = runtime?.log ?? console.log;
|
|
67
|
+
log("Clearing all WebSocket manager caches");
|
|
68
|
+
for (const manager of wsManagerCache.values()) {
|
|
69
|
+
manager.disconnect();
|
|
70
|
+
}
|
|
71
|
+
wsManagerCache.clear();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the number of cached managers.
|
|
75
|
+
*/
|
|
76
|
+
function getCachedManagerCount() {
|
|
77
|
+
return wsManagerCache.size;
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OpenClawConfig } from "openclaw/dist/plugin-sdk/index.js";
|
|
2
|
+
import type { XiaoYiChannelConfig } from "./types.js";
|
|
3
|
+
type ClawdbotConfig = OpenClawConfig;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve XiaoYi channel configuration from OpenClaw config.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveXYConfig(cfg: ClawdbotConfig): XiaoYiChannelConfig;
|
|
8
|
+
/**
|
|
9
|
+
* List XiaoYi channel account IDs.
|
|
10
|
+
* Single account mode - always returns ["default"].
|
|
11
|
+
*/
|
|
12
|
+
export declare function listXYAccountIds(cfg: ClawdbotConfig): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Get default XiaoYi channel account ID.
|
|
15
|
+
* Single account mode - always returns "default".
|
|
16
|
+
*/
|
|
17
|
+
export declare function getDefaultXYAccountId(cfg: ClawdbotConfig): string | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveXYConfig = resolveXYConfig;
|
|
4
|
+
exports.listXYAccountIds = listXYAccountIds;
|
|
5
|
+
exports.getDefaultXYAccountId = getDefaultXYAccountId;
|
|
6
|
+
/**
|
|
7
|
+
* Resolve XiaoYi channel configuration from OpenClaw config.
|
|
8
|
+
*/
|
|
9
|
+
function resolveXYConfig(cfg) {
|
|
10
|
+
const channelConfig = cfg?.channels?.xiaoyi;
|
|
11
|
+
if (!channelConfig) {
|
|
12
|
+
throw new Error("XiaoYi channel configuration not found");
|
|
13
|
+
}
|
|
14
|
+
return channelConfig;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* List XiaoYi channel account IDs.
|
|
18
|
+
* Single account mode - always returns ["default"].
|
|
19
|
+
*/
|
|
20
|
+
function listXYAccountIds(cfg) {
|
|
21
|
+
const channelConfig = cfg?.channels?.xiaoyi;
|
|
22
|
+
if (!channelConfig || !channelConfig.enabled) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
return ["default"];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get default XiaoYi channel account ID.
|
|
29
|
+
* Single account mode - always returns "default".
|
|
30
|
+
*/
|
|
31
|
+
function getDefaultXYAccountId(cfg) {
|
|
32
|
+
const channelConfig = cfg?.channels?.xiaoyi;
|
|
33
|
+
if (!channelConfig || !channelConfig.enabled) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return "default";
|
|
37
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { XiaoYiChannelConfig, A2ACommand } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for sending an A2A response.
|
|
4
|
+
*/
|
|
5
|
+
export interface SendA2AResponseParams {
|
|
6
|
+
config: XiaoYiChannelConfig;
|
|
7
|
+
sessionId: string;
|
|
8
|
+
taskId: string;
|
|
9
|
+
messageId: string;
|
|
10
|
+
text?: string;
|
|
11
|
+
append: boolean;
|
|
12
|
+
final: boolean;
|
|
13
|
+
files?: Array<{
|
|
14
|
+
fileName: string;
|
|
15
|
+
fileType: string;
|
|
16
|
+
fileId: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Send an A2A artifact update response.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sendA2AResponse(params: SendA2AResponseParams): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Parameters for sending a reasoning text update (intermediate, streamed).
|
|
25
|
+
*/
|
|
26
|
+
export interface SendReasoningTextUpdateParams {
|
|
27
|
+
config: XiaoYiChannelConfig;
|
|
28
|
+
sessionId: string;
|
|
29
|
+
taskId: string;
|
|
30
|
+
messageId: string;
|
|
31
|
+
text: string;
|
|
32
|
+
append?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Send an A2A artifact-update with reasoningText part.
|
|
36
|
+
* Used for onToolStart, onToolResult, onReasoningStream, onReasoningEnd, onPartialReply.
|
|
37
|
+
* append=true, final=false, lastChunk=true, text is suffixed with newline for markdown rendering.
|
|
38
|
+
*/
|
|
39
|
+
export declare function sendReasoningTextUpdate(params: SendReasoningTextUpdateParams): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Parameters for sending a status update.
|
|
42
|
+
*/
|
|
43
|
+
export interface SendStatusUpdateParams {
|
|
44
|
+
config: XiaoYiChannelConfig;
|
|
45
|
+
sessionId: string;
|
|
46
|
+
taskId: string;
|
|
47
|
+
messageId: string;
|
|
48
|
+
text: string;
|
|
49
|
+
state: "submitted" | "working" | "input-required" | "completed" | "canceled" | "failed" | "unknown";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Send an A2A task status update.
|
|
53
|
+
* Follows A2A protocol standard format with nested status object.
|
|
54
|
+
*/
|
|
55
|
+
export declare function sendStatusUpdate(params: SendStatusUpdateParams): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Parameters for sending a command.
|
|
58
|
+
*/
|
|
59
|
+
export interface SendCommandParams {
|
|
60
|
+
config: XiaoYiChannelConfig;
|
|
61
|
+
sessionId: string;
|
|
62
|
+
taskId: string;
|
|
63
|
+
messageId: string;
|
|
64
|
+
command: A2ACommand;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Send a command as an artifact update (final=false).
|
|
68
|
+
*/
|
|
69
|
+
export declare function sendCommand(params: SendCommandParams): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Parameters for sending a clearContext response.
|
|
72
|
+
*/
|
|
73
|
+
export interface SendClearContextResponseParams {
|
|
74
|
+
config: XiaoYiChannelConfig;
|
|
75
|
+
sessionId: string;
|
|
76
|
+
messageId: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Send a clearContext response.
|
|
80
|
+
*/
|
|
81
|
+
export declare function sendClearContextResponse(params: SendClearContextResponseParams): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Parameters for sending a tasks/cancel response.
|
|
84
|
+
*/
|
|
85
|
+
export interface SendTasksCancelResponseParams {
|
|
86
|
+
config: XiaoYiChannelConfig;
|
|
87
|
+
sessionId: string;
|
|
88
|
+
taskId: string;
|
|
89
|
+
messageId: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Send a tasks/cancel response.
|
|
93
|
+
*/
|
|
94
|
+
export declare function sendTasksCancelResponse(params: SendTasksCancelResponseParams): Promise<void>;
|