@xiaozhi-pro/openclaw-plugin 1.0.2 → 1.0.4
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 +1 -1
- package/dist/setup-entry.d.ts +1 -1
- package/dist/src/accounts.js +3 -2
- package/dist/src/channel.d.ts +1 -2
- package/dist/src/channel.js +11 -58
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const entry: import("openclaw/plugin-sdk/channel-entry-contract").BundledChannelEntryContract<import("openclaw/plugin-sdk/core").ChannelPlugin>;
|
|
1
|
+
declare const entry: import("openclaw/plugin-sdk/channel-entry-contract").BundledChannelEntryContract<import("openclaw/plugin-sdk/channel-core").ChannelPlugin>;
|
|
2
2
|
export default entry;
|
package/dist/setup-entry.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("openclaw/plugin-sdk/channel-entry-contract").BundledChannelSetupEntryContract<import("openclaw/plugin-sdk/core").ChannelPlugin>;
|
|
1
|
+
declare const _default: import("openclaw/plugin-sdk/channel-entry-contract").BundledChannelSetupEntryContract<import("openclaw/plugin-sdk/channel-core").ChannelPlugin>;
|
|
2
2
|
export default _default;
|
package/dist/src/accounts.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
|
2
|
-
import { normalizeLowercaseStringOrEmpty
|
|
2
|
+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
|
+
import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from";
|
|
3
4
|
import { XIAOZHI_PRO_WS_URL } from "./types.js";
|
|
4
5
|
export function listAccountIds(cfg) {
|
|
5
6
|
const section = cfg.channels?.["xiaozhi-pro"];
|
|
@@ -19,7 +20,7 @@ export function resolveAccount(cfg, accountId) {
|
|
|
19
20
|
enabled: raw.enabled !== false,
|
|
20
21
|
token: normalizeLowercaseStringOrEmpty(raw.token),
|
|
21
22
|
dmPolicy: raw.dmPolicy ?? "open",
|
|
22
|
-
allowedUserIds:
|
|
23
|
+
allowedUserIds: formatAllowFromLowercase(raw.allowedUserIds ?? raw.allowFrom),
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
/** 获取小智Pro WS URL(固定地址) */
|
package/dist/src/channel.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type ChannelPlugin
|
|
1
|
+
import { type ChannelPlugin } from "openclaw/plugin-sdk/channel-core";
|
|
2
2
|
import { type ResolvedXiaozhiProAccount } from "./accounts.js";
|
|
3
3
|
export declare const xiaozhiProPlugin: ChannelPlugin<ResolvedXiaozhiProAccount>;
|
|
4
|
-
export { defineChannelPluginEntry };
|
package/dist/src/channel.js
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
// 1. gateway.startAccount → 建立 WS 连接到小智Pro 服务端
|
|
5
5
|
// 2. 收到 WS 消息 → 通过 rt.channel.inbound.run() 分发给 agent
|
|
6
6
|
// 3. agent 回复 → 通过 WS 发回小智Pro
|
|
7
|
-
import { createChatChannelPlugin,
|
|
8
|
-
import { waitUntilAbort } from "openclaw/plugin-sdk/channel-
|
|
9
|
-
import { defineChannelMessageAdapter, createMessageReceiptFromOutboundResults, } from "openclaw/plugin-sdk/channel-outbound";
|
|
7
|
+
import { createChatChannelPlugin, } from "openclaw/plugin-sdk/channel-core";
|
|
8
|
+
import { waitUntilAbort } from "openclaw/plugin-sdk/channel-runtime";
|
|
10
9
|
import { createEmptyChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
|
|
11
10
|
import { createHybridChannelConfigAdapter, createScopedDmSecurityResolver, } from "openclaw/plugin-sdk/channel-config-helpers";
|
|
12
11
|
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
|
@@ -17,34 +16,7 @@ import { connectXiaozhiProWs, sendXiaozhiProWsMessage, } from "./ws-client.js";
|
|
|
17
16
|
import { isDuplicateMessage } from "./dedup.js";
|
|
18
17
|
const CHANNEL_ID = "xiaozhi-pro";
|
|
19
18
|
// ============================================================================
|
|
20
|
-
// 1.
|
|
21
|
-
// ============================================================================
|
|
22
|
-
const xiaozhiProMessageAdapter = defineChannelMessageAdapter({
|
|
23
|
-
id: CHANNEL_ID,
|
|
24
|
-
durableFinal: {
|
|
25
|
-
capabilities: { text: true, media: false, messageSendingHooks: false },
|
|
26
|
-
},
|
|
27
|
-
send: {
|
|
28
|
-
text: async (ctx) => {
|
|
29
|
-
const account = resolveAccount(ctx.cfg, ctx.accountId ?? DEFAULT_ACCOUNT_ID);
|
|
30
|
-
const sent = await sendXiaozhiProWsMessage(account, ctx.to, ctx.text);
|
|
31
|
-
return {
|
|
32
|
-
channel: CHANNEL_ID,
|
|
33
|
-
messageId: sent.messageId,
|
|
34
|
-
chatId: ctx.to,
|
|
35
|
-
receipt: createMessageReceiptFromOutboundResults({
|
|
36
|
-
results: [
|
|
37
|
-
{ channel: CHANNEL_ID, messageId: sent.messageId, chatId: ctx.to, conversationId: ctx.to },
|
|
38
|
-
],
|
|
39
|
-
threadId: ctx.to,
|
|
40
|
-
kind: "text",
|
|
41
|
-
}),
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
// ============================================================================
|
|
47
|
-
// 2. 插件定义
|
|
19
|
+
// 1. 插件定义
|
|
48
20
|
// ============================================================================
|
|
49
21
|
export const xiaozhiProPlugin = createChatChannelPlugin({
|
|
50
22
|
base: {
|
|
@@ -91,7 +63,7 @@ export const xiaozhiProPlugin = createChatChannelPlugin({
|
|
|
91
63
|
},
|
|
92
64
|
directory: createEmptyChannelDirectoryAdapter(),
|
|
93
65
|
// ============================================================================
|
|
94
|
-
//
|
|
66
|
+
// 2. gateway.startAccount:建立 WS 连接,收消息分发给 agent
|
|
95
67
|
// ============================================================================
|
|
96
68
|
gateway: {
|
|
97
69
|
startAccount: async (ctx) => {
|
|
@@ -123,7 +95,6 @@ export const xiaozhiProPlugin = createChatChannelPlugin({
|
|
|
123
95
|
});
|
|
124
96
|
},
|
|
125
97
|
},
|
|
126
|
-
message: xiaozhiProMessageAdapter,
|
|
127
98
|
agentPrompt: {
|
|
128
99
|
messageToolHints: () => [
|
|
129
100
|
"",
|
|
@@ -157,9 +128,6 @@ export const xiaozhiProPlugin = createChatChannelPlugin({
|
|
|
157
128
|
outbound: {
|
|
158
129
|
deliveryMode: "gateway",
|
|
159
130
|
textChunkLimit: 2000,
|
|
160
|
-
// TODO: 流式回复占位 — WS 天然支持增量推送,未来可接入
|
|
161
|
-
// OpenClaw 的流式管道(live preview → finalize),届时需实现
|
|
162
|
-
// sendStreamStart / sendStreamChunk / sendStreamFinalize
|
|
163
131
|
sendText: async (ctx) => {
|
|
164
132
|
const account = resolveAccount(ctx.cfg ?? {}, ctx.accountId ?? null);
|
|
165
133
|
const sent = await sendXiaozhiProWsMessage(account, ctx.to, ctx.text);
|
|
@@ -167,13 +135,6 @@ export const xiaozhiProPlugin = createChatChannelPlugin({
|
|
|
167
135
|
channel: CHANNEL_ID,
|
|
168
136
|
messageId: sent.messageId,
|
|
169
137
|
chatId: ctx.to,
|
|
170
|
-
receipt: createMessageReceiptFromOutboundResults({
|
|
171
|
-
results: [
|
|
172
|
-
{ channel: CHANNEL_ID, messageId: sent.messageId, chatId: ctx.to, conversationId: ctx.to },
|
|
173
|
-
],
|
|
174
|
-
threadId: ctx.to,
|
|
175
|
-
kind: "text",
|
|
176
|
-
}),
|
|
177
138
|
};
|
|
178
139
|
},
|
|
179
140
|
},
|
|
@@ -182,7 +143,7 @@ export const xiaozhiProPlugin = createChatChannelPlugin({
|
|
|
182
143
|
// 入站分发:小智Pro WS 消息 → OpenClaw agent
|
|
183
144
|
// ============================================================================
|
|
184
145
|
async function dispatchXiaozhiProInboundEvent(params) {
|
|
185
|
-
//
|
|
146
|
+
// 去重:跳过已处理过的消息
|
|
186
147
|
if (isDuplicateMessage(params.msg.messageId)) {
|
|
187
148
|
return;
|
|
188
149
|
}
|
|
@@ -255,18 +216,12 @@ async function dispatchXiaozhiProInboundEvent(params) {
|
|
|
255
216
|
if (text) {
|
|
256
217
|
await sendXiaozhiProWsMessage(params.account, params.msg.senderId, text);
|
|
257
218
|
}
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
conversationId: params.msg.senderId,
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
threadId: params.msg.senderId,
|
|
268
|
-
kind: "text",
|
|
269
|
-
});
|
|
219
|
+
return {
|
|
220
|
+
channel: CHANNEL_ID,
|
|
221
|
+
messageId: `reply-${Date.now()}`,
|
|
222
|
+
chatId: params.msg.senderId,
|
|
223
|
+
conversationId: params.msg.senderId,
|
|
224
|
+
};
|
|
270
225
|
},
|
|
271
226
|
},
|
|
272
227
|
};
|
|
@@ -274,5 +229,3 @@ async function dispatchXiaozhiProInboundEvent(params) {
|
|
|
274
229
|
},
|
|
275
230
|
});
|
|
276
231
|
}
|
|
277
|
-
// 入口定义(外部插件用 defineChannelPluginEntry)
|
|
278
|
-
export { defineChannelPluginEntry };
|