openclaw-xiaoyou 1.4.0 → 1.4.2
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/package.json +1 -1
- package/src/channel.ts +33 -7
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { createEnterpriseClient, type EnterpriseClient } from "./enterprise-clie
|
|
|
11
11
|
// ─── 运行时状态 ──────────────────────────────────────
|
|
12
12
|
|
|
13
13
|
let _client: EnterpriseClient | null = null;
|
|
14
|
+
/** 记录最后一个活跃的 conversationId,用于 cron delivery 兜底 */
|
|
15
|
+
let _lastConversationId: string | null = null;
|
|
14
16
|
|
|
15
17
|
let _runtime: any = null;
|
|
16
18
|
export function setRuntime(rt: any) { _runtime = rt; }
|
|
@@ -138,6 +140,9 @@ export const xiayouPlugin = {
|
|
|
138
140
|
const conversationId = msg.conversationId;
|
|
139
141
|
const inboundMessageId = msg.messageId;
|
|
140
142
|
const text = msg.text ?? "";
|
|
143
|
+
|
|
144
|
+
// 记录最后活跃的 conversationId,供 cron delivery 兜底使用
|
|
145
|
+
_lastConversationId = conversationId;
|
|
141
146
|
const accountId = account?.accountId || "default";
|
|
142
147
|
|
|
143
148
|
// 1. 路由
|
|
@@ -155,7 +160,7 @@ export const xiayouPlugin = {
|
|
|
155
160
|
channel: "Xiaoyou",
|
|
156
161
|
from: fromLabel,
|
|
157
162
|
timestamp: Date.now(),
|
|
158
|
-
body: text
|
|
163
|
+
body: `[系统信息] 当前 conversationId: ${conversationId} | 当前 senderId: ${senderId}\n\n${text}`,
|
|
159
164
|
chatType: "direct",
|
|
160
165
|
sender: { name: senderName, id: senderId },
|
|
161
166
|
envelope: envelopeOptions,
|
|
@@ -276,6 +281,22 @@ export const xiayouPlugin = {
|
|
|
276
281
|
},
|
|
277
282
|
},
|
|
278
283
|
|
|
284
|
+
// ── Target 解析(让 Gateway delivery 系统识别 xiaoyou target)──
|
|
285
|
+
normalizeTarget: (target: string) => {
|
|
286
|
+
// 去掉可能的 xiaoyou: 前缀
|
|
287
|
+
const normalized = target.replace(/^xiaoyou:/i, "");
|
|
288
|
+
return { ok: true, to: normalized };
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
targetResolver: {
|
|
292
|
+
looksLikeId: (id: string): boolean => {
|
|
293
|
+
// 支持 conv-xxx 格式和任意非空字符串
|
|
294
|
+
const normalized = id.replace(/^xiaoyou:/i, "");
|
|
295
|
+
return normalized.length > 0;
|
|
296
|
+
},
|
|
297
|
+
hint: "conversationId (e.g. conv-125)",
|
|
298
|
+
},
|
|
299
|
+
|
|
279
300
|
// ── Outbound 出站(符合 ChannelPluginOutbound 接口)──────
|
|
280
301
|
outbound: {
|
|
281
302
|
deliveryMode: "direct" as const,
|
|
@@ -286,19 +307,22 @@ export const xiayouPlugin = {
|
|
|
286
307
|
return { channel: "xiaoyou", error: new Error("xiaoyou: not connected") };
|
|
287
308
|
}
|
|
288
309
|
|
|
310
|
+
// 如果 to 为空,使用最后活跃的 conversationId 兜底
|
|
311
|
+
const targetTo = to || _lastConversationId || "cron-delivery";
|
|
312
|
+
|
|
289
313
|
const reply = {
|
|
290
314
|
type: "reply" as const,
|
|
291
|
-
conversationId:
|
|
315
|
+
conversationId: targetTo,
|
|
292
316
|
messageId: `xiaoyou-${Date.now()}`,
|
|
293
317
|
replyToMessageId: replyToId,
|
|
294
318
|
senderId: to,
|
|
295
|
-
source: "scheduled_task" as const,
|
|
319
|
+
...(replyToId ? {} : { source: "scheduled_task" as const }),
|
|
296
320
|
text: text,
|
|
297
321
|
timestamp: Date.now(),
|
|
298
322
|
};
|
|
299
323
|
|
|
300
324
|
_client.sendReply(reply);
|
|
301
|
-
console.log(`[xiaoyou][outbound] sendText to=${
|
|
325
|
+
console.log(`[xiaoyou][outbound] sendText to=${targetTo}, text=${text?.substring(0, 50)}`);
|
|
302
326
|
return { channel: "xiaoyou", messageId: reply.messageId };
|
|
303
327
|
},
|
|
304
328
|
|
|
@@ -307,20 +331,22 @@ export const xiayouPlugin = {
|
|
|
307
331
|
return { channel: "xiaoyou", error: new Error("xiaoyou: not connected") };
|
|
308
332
|
}
|
|
309
333
|
|
|
334
|
+
const targetTo = to || _lastConversationId || "cron-delivery";
|
|
335
|
+
|
|
310
336
|
const reply = {
|
|
311
337
|
type: "reply" as const,
|
|
312
|
-
conversationId:
|
|
338
|
+
conversationId: targetTo,
|
|
313
339
|
messageId: `xiaoyou-${Date.now()}`,
|
|
314
340
|
replyToMessageId: replyToId,
|
|
315
341
|
senderId: to,
|
|
316
|
-
source: "scheduled_task" as const,
|
|
342
|
+
...(replyToId ? {} : { source: "scheduled_task" as const }),
|
|
317
343
|
text: text ?? "",
|
|
318
344
|
mediaUrls: mediaUrl ? [mediaUrl] : [],
|
|
319
345
|
timestamp: Date.now(),
|
|
320
346
|
};
|
|
321
347
|
|
|
322
348
|
_client.sendReply(reply);
|
|
323
|
-
console.log(`[xiaoyou][outbound] sendMedia to=${
|
|
349
|
+
console.log(`[xiaoyou][outbound] sendMedia to=${targetTo}`);
|
|
324
350
|
return { channel: "xiaoyou", messageId: reply.messageId };
|
|
325
351
|
},
|
|
326
352
|
},
|