openclaw-xiaoyou 1.4.5 → 1.4.6
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 +21 -20
- package/src/types.ts +6 -0
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* xiaoyou ChannelPlugin 实现
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* 与企业服务的 WebSocket
|
|
4
|
+
* 运行�?OpenClaw Gateway 进程内,通过 gateway adapter 管理
|
|
5
|
+
* 与企业服务的 WebSocket 连接生命周期�?
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { ResolvedAccount } from "./types.js";
|
|
9
9
|
import { createEnterpriseClient, type EnterpriseClient } from "./enterprise-client.js";
|
|
10
10
|
|
|
11
|
-
// ───
|
|
11
|
+
// ─── 运行时状�?──────────────────────────────────────
|
|
12
12
|
|
|
13
13
|
let _client: EnterpriseClient | null = null;
|
|
14
|
-
/** 记录最后一个活跃的 conversationId
|
|
14
|
+
/** 记录最后一个活跃的 conversationId,用�?cron delivery 兜底 */
|
|
15
15
|
let _lastConversationId: string | null = null;
|
|
16
16
|
|
|
17
17
|
let _runtime: any = null;
|
|
@@ -102,8 +102,8 @@ export const xiayouPlugin = {
|
|
|
102
102
|
startAccount: async (ctx: any) => {
|
|
103
103
|
const { account, cfg, log } = ctx;
|
|
104
104
|
|
|
105
|
-
// 使用 register 时注入的 runtime(有 channel.reply
|
|
106
|
-
// 注意:ctx.runtime 只有 log/error/exit
|
|
105
|
+
// 使用 register 时注入的 runtime(有 channel.reply 等完�?API�?
|
|
106
|
+
// 注意:ctx.runtime 只有 log/error/exit,不能用它覆�?
|
|
107
107
|
const section = account?.config || getChannelConfig(cfg);
|
|
108
108
|
const logger = log || console;
|
|
109
109
|
|
|
@@ -139,6 +139,7 @@ export const xiayouPlugin = {
|
|
|
139
139
|
const senderName = msg.senderName ?? msg.senderId;
|
|
140
140
|
const conversationId = msg.conversationId;
|
|
141
141
|
const inboundMessageId = msg.messageId;
|
|
142
|
+
const inboundSn = msg.sn || msg.messageId;
|
|
142
143
|
const text = msg.text ?? "";
|
|
143
144
|
const metadata = msg.metadata ?? undefined;
|
|
144
145
|
|
|
@@ -154,7 +155,7 @@ export const xiayouPlugin = {
|
|
|
154
155
|
peer: { kind: "direct", id: senderId },
|
|
155
156
|
});
|
|
156
157
|
|
|
157
|
-
// 2.
|
|
158
|
+
// 2. 格式化入站消�?
|
|
158
159
|
const fromLabel = `${senderName} (${senderId})`;
|
|
159
160
|
const envelopeOptions = rt.channel.reply.resolveEnvelopeFormatOptions(cfg);
|
|
160
161
|
const body = rt.channel.reply.formatInboundEnvelope({
|
|
@@ -167,7 +168,7 @@ export const xiayouPlugin = {
|
|
|
167
168
|
envelope: envelopeOptions,
|
|
168
169
|
});
|
|
169
170
|
|
|
170
|
-
// 3.
|
|
171
|
+
// 3. 构建上下�?
|
|
171
172
|
const inboundCtx = rt.channel.reply.finalizeInboundContext({
|
|
172
173
|
Body: body,
|
|
173
174
|
RawBody: text,
|
|
@@ -186,10 +187,10 @@ export const xiayouPlugin = {
|
|
|
186
187
|
Timestamp: Date.now(),
|
|
187
188
|
});
|
|
188
189
|
|
|
189
|
-
// 4. 分发并获取回复(流式
|
|
190
|
+
// 4. 分发并获取回复(流式 �?按标点拆分)
|
|
190
191
|
//
|
|
191
|
-
// Gateway
|
|
192
|
-
//
|
|
192
|
+
// Gateway �?block streaming 会多次调�?deliver,每次一�?block�?
|
|
193
|
+
// 我们�?deliver 内部进一步按标点/换行拆分,实现更细粒度的流式推送�?
|
|
193
194
|
//
|
|
194
195
|
const replyMessageId = `xiaoyou-${Date.now()}`;
|
|
195
196
|
let chunkSeq = 1;
|
|
@@ -212,7 +213,7 @@ export const xiayouPlugin = {
|
|
|
212
213
|
type: "reply",
|
|
213
214
|
conversationId,
|
|
214
215
|
messageId: replyMessageId,
|
|
215
|
-
|
|
216
|
+
sn: inboundSn,
|
|
216
217
|
senderId,
|
|
217
218
|
text: textToSend,
|
|
218
219
|
...(metadata ? { metadata } : {}),
|
|
@@ -230,7 +231,7 @@ export const xiayouPlugin = {
|
|
|
230
231
|
type: "reply",
|
|
231
232
|
conversationId,
|
|
232
233
|
messageId: replyMessageId,
|
|
233
|
-
|
|
234
|
+
sn: inboundSn,
|
|
234
235
|
senderId,
|
|
235
236
|
text: fullText,
|
|
236
237
|
...(metadata ? { metadata } : {}),
|
|
@@ -249,7 +250,7 @@ export const xiayouPlugin = {
|
|
|
249
250
|
type: "reply",
|
|
250
251
|
conversationId,
|
|
251
252
|
messageId: replyMessageId,
|
|
252
|
-
|
|
253
|
+
sn: inboundSn,
|
|
253
254
|
senderId,
|
|
254
255
|
text: fullText,
|
|
255
256
|
...(metadata ? { metadata } : {}),
|
|
@@ -267,7 +268,7 @@ export const xiayouPlugin = {
|
|
|
267
268
|
_client = client;
|
|
268
269
|
logger.info("[xiaoyou] gateway started");
|
|
269
270
|
|
|
270
|
-
// 保持 startAccount
|
|
271
|
+
// 保持 startAccount 挂起,直�?abortSignal 触发
|
|
271
272
|
return new Promise<void>((resolve) => {
|
|
272
273
|
if (ctx.abortSignal) {
|
|
273
274
|
ctx.abortSignal.addEventListener("abort", () => {
|
|
@@ -287,7 +288,7 @@ export const xiayouPlugin = {
|
|
|
287
288
|
|
|
288
289
|
// ── Target 解析(让 Gateway delivery 系统识别 xiaoyou target)──
|
|
289
290
|
normalizeTarget: (target: string) => {
|
|
290
|
-
// 如果 target
|
|
291
|
+
// 如果 target 为空,返回默认�?"schedule",避�?Gateway �?"requires target"
|
|
291
292
|
const normalized = (target || "schedule").replace(/^xiaoyou:/i, "");
|
|
292
293
|
return { ok: true, to: normalized || "schedule" };
|
|
293
294
|
},
|
|
@@ -301,7 +302,7 @@ export const xiayouPlugin = {
|
|
|
301
302
|
hint: "conversationId (e.g. conv-125)",
|
|
302
303
|
},
|
|
303
304
|
|
|
304
|
-
// ── Outbound
|
|
305
|
+
// ── Outbound 出站(符�?ChannelPluginOutbound 接口)──────
|
|
305
306
|
outbound: {
|
|
306
307
|
deliveryMode: "direct" as const,
|
|
307
308
|
textChunkLimit: 2000,
|
|
@@ -319,7 +320,7 @@ export const xiayouPlugin = {
|
|
|
319
320
|
type: "reply" as const,
|
|
320
321
|
conversationId: targetTo,
|
|
321
322
|
messageId: `xiaoyou-${Date.now()}`,
|
|
322
|
-
|
|
323
|
+
sn: replyToId,
|
|
323
324
|
senderId: to,
|
|
324
325
|
text: text,
|
|
325
326
|
timestamp: Date.now(),
|
|
@@ -341,7 +342,7 @@ export const xiayouPlugin = {
|
|
|
341
342
|
type: "reply" as const,
|
|
342
343
|
conversationId: targetTo,
|
|
343
344
|
messageId: `xiaoyou-${Date.now()}`,
|
|
344
|
-
|
|
345
|
+
sn: replyToId,
|
|
345
346
|
senderId: to,
|
|
346
347
|
text: text ?? "",
|
|
347
348
|
mediaUrls: mediaUrl ? [mediaUrl] : [],
|
|
@@ -354,7 +355,7 @@ export const xiayouPlugin = {
|
|
|
354
355
|
},
|
|
355
356
|
},
|
|
356
357
|
|
|
357
|
-
// ── Status
|
|
358
|
+
// ── Status 状态检�?────────────────────────────────
|
|
358
359
|
status: {
|
|
359
360
|
describe: async ({ account }: any) => {
|
|
360
361
|
const issues: Array<{ severity: string; message: string }> = [];
|
package/src/types.ts
CHANGED
|
@@ -32,6 +32,9 @@ export type InboundMessage = {
|
|
|
32
32
|
conversationId: string;
|
|
33
33
|
senderId: string;
|
|
34
34
|
senderName?: string;
|
|
35
|
+
/** 流水号,用于请求-回复关联 */
|
|
36
|
+
sn?: string;
|
|
37
|
+
/** @deprecated 使用 sn 代替 */
|
|
35
38
|
messageId?: string;
|
|
36
39
|
text?: string;
|
|
37
40
|
attachments?: Attachment[];
|
|
@@ -59,6 +62,9 @@ export type OutboundReply = {
|
|
|
59
62
|
type: "reply";
|
|
60
63
|
conversationId: string;
|
|
61
64
|
messageId: string;
|
|
65
|
+
/** 流水号,关联入站消息的 sn */
|
|
66
|
+
sn?: string;
|
|
67
|
+
/** @deprecated 使用 sn 代替 */
|
|
62
68
|
replyToMessageId?: string;
|
|
63
69
|
senderId?: string;
|
|
64
70
|
text: string;
|