openclaw-xiaoyou 1.2.1 → 1.2.3

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/docs/SKILL.md CHANGED
@@ -5,48 +5,48 @@ description: Use when users want to install, upgrade, uninstall, configure, or t
5
5
 
6
6
  # 小优 Channel 安装入口
7
7
 
8
- 小优 channel 安装、升级、卸载统一使用远程脚本:
8
+ 小优 channel 安装、升级、卸载统一使用远程脚本�?
9
9
 
10
10
  ```bash
11
- https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38aec3ba/install-xiaoyou.sh
11
+ https://d10.tfdl.net/public/2026-05-06/14dbf63d-d0aa-4b5d-bdd6-47eddb455f36/install-xiaoyou.sh
12
12
  ```
13
13
 
14
- 不要把 OpenClaw 的底层安装命令拆散执行。除非远程脚本失败且需要排障,否则直接调用 `install-xiaoyou.sh`。
14
+ 不要�?OpenClaw 的底层安装命令拆散执行。除非远程脚本失败且需要排障,否则直接调用 `install-xiaoyou.sh`�?
15
15
 
16
- ## 触发词
16
+ ## 触发�?
17
17
 
18
18
  - "安装小优" / "小优安装"
19
19
  - "小优接入" / "接入小优"
20
20
  - "配置 xiaoyou" / "xiaoyou 配置"
21
21
  - "升级小优" / "更新小优"
22
22
  - "卸载小优" / "移除小优"
23
- - "我想用小优" / "启用小优"
23
+ - "我想用小�? / "启用小优"
24
24
  - "小优 channel" / "xiaoyou channel"
25
25
 
26
26
  ## 标准执行
27
27
 
28
- 优先直接通过 `curl | bash` 执行远程脚本:
28
+ 优先直接通过 `curl | bash` 执行远程脚本�?
29
29
 
30
30
  ```bash
31
- curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38aec3ba/install-xiaoyou.sh | bash -s -- --ws-url ws://aiws-sim.haiersmarthomes.com:11055/xiaoyou/claw --token <AccessToken>
31
+ curl -fsSL https://d10.tfdl.net/public/2026-05-06/14dbf63d-d0aa-4b5d-bdd6-47eddb455f36/install-xiaoyou.sh | bash -s -- --ws-url ws://aiws-sim.haiersmarthomes.com:11055/xiaoyou/claw --token <AccessToken>
32
32
  ```
33
33
 
34
34
  ### 参数说明
35
35
 
36
36
  | 参数 | 必填 | 说明 |
37
37
  |------|------|------|
38
- | `--ws-url <url>` | 首次安装 | 企业 WebSocket 服务地址,默认 `ws://aiws-sim.haiersmarthomes.com:11055/xiaoyou/claw` |
39
- | `--token <token>` | 首次安装 | 企业服务认证 Token |
40
- | `--version <ver>` | | 指定 openclaw-xiaoyou 版本,默认 latest |
41
- | `--check-only` | | 只输出计划,不执行真实改动 |
42
- | `uninstall` | | 卸载小优 channel |
38
+ | `--ws-url <url>` | �?首次安装 | 企业 WebSocket 服务地址,默�?`ws://aiws-sim.haiersmarthomes.com:11055/xiaoyou/claw` |
39
+ | `--token <token>` | �?首次安装 | 企业服务认证 Token |
40
+ | `--version <ver>` | �?| 指定 openclaw-xiaoyou 版本,默�?latest |
41
+ | `--check-only` | �?| 只输出计划,不执行真实改�?|
42
+ | `uninstall` | �?| 卸载小优 channel |
43
43
 
44
44
  ### 首次安装
45
45
 
46
- 用户必须提供 `--ws-url` 和 `--token`:
46
+ 用户必须提供 `--ws-url` �?`--token`�?
47
47
 
48
48
  ```bash
49
- curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38aec3ba/install-xiaoyou.sh | bash -s -- --ws-url ws://aiws-sim.haiersmarthomes.com:11055/xiaoyou/claw --token my-enterprise-token
49
+ curl -fsSL https://d10.tfdl.net/public/2026-05-06/14dbf63d-d0aa-4b5d-bdd6-47eddb455f36/install-xiaoyou.sh | bash -s -- --ws-url ws://aiws-sim.haiersmarthomes.com:11055/xiaoyou/claw --token my-enterprise-token
50
50
  ```
51
51
 
52
52
  ### 升级
@@ -54,30 +54,30 @@ curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38
54
54
  已安装后的升级可以不传参数,脚本会复用现有配置:
55
55
 
56
56
  ```bash
57
- curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38aec3ba/install-xiaoyou.sh | bash -s --
57
+ curl -fsSL https://d10.tfdl.net/public/2026-05-06/14dbf63d-d0aa-4b5d-bdd6-47eddb455f36/install-xiaoyou.sh | bash -s --
58
58
  ```
59
59
 
60
- 如果升级时传入 `--ws-url` 或 `--token`,会覆盖现有配置。
60
+ 如果升级时传�?`--ws-url` �?`--token`,会覆盖现有配置�?
61
61
 
62
62
  ### 指定版本
63
63
 
64
64
  ```bash
65
- curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38aec3ba/install-xiaoyou.sh | bash -s -- --version 1.0.2 --ws-url ws://aiws-sim.haiersmarthomes.com:11055/xiaoyou/claw --token my-token
65
+ curl -fsSL https://d10.tfdl.net/public/2026-05-06/14dbf63d-d0aa-4b5d-bdd6-47eddb455f36/install-xiaoyou.sh | bash -s -- --version 1.0.2 --ws-url ws://aiws-sim.haiersmarthomes.com:11055/xiaoyou/claw --token my-token
66
66
  ```
67
67
 
68
68
  ## 卸载
69
69
 
70
70
  ```bash
71
- curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38aec3ba/install-xiaoyou.sh | bash -s -- uninstall
71
+ curl -fsSL https://d10.tfdl.net/public/2026-05-06/14dbf63d-d0aa-4b5d-bdd6-47eddb455f36/install-xiaoyou.sh | bash -s -- uninstall
72
72
  ```
73
73
 
74
- 卸载会删除 xiaoyou channel 配置、插件记录和扩展目录。
74
+ 卸载会删�?xiaoyou channel 配置、插件记录和扩展目录�?
75
75
 
76
76
  ## 预检
77
77
 
78
78
  ```bash
79
- curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38aec3ba/install-xiaoyou.sh | bash -s -- --check-only
80
- curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38aec3ba/install-xiaoyou.sh | bash -s -- uninstall --check-only
79
+ curl -fsSL https://d10.tfdl.net/public/2026-05-06/14dbf63d-d0aa-4b5d-bdd6-47eddb455f36/install-xiaoyou.sh | bash -s -- --check-only
80
+ curl -fsSL https://d10.tfdl.net/public/2026-05-06/14dbf63d-d0aa-4b5d-bdd6-47eddb455f36/install-xiaoyou.sh | bash -s -- uninstall --check-only
81
81
  ```
82
82
 
83
83
  ## 失败处理
@@ -89,22 +89,22 @@ curl -fsSL https://d10.tfdl.net/public/2026-05-06/e466d49d-4c5c-4fca-88dd-d69a38
89
89
  | 缺少 `--token` | 要求用户提供企业服务认证 Token |
90
90
  | 未检测到 OpenClaw | 提示用户先安装并启动 OpenClaw |
91
91
  | npm latest 查询失败 | 可让脚本继续幂等安装,或指定 `--version` |
92
- | wsUrl 格式不合法 | 地址必须以 `ws://` 或 `wss://` 开头 |
92
+ | wsUrl 格式不合�?| 地址必须�?`ws://` �?`wss://` 开�?|
93
93
 
94
- ## 脚本做了什么
94
+ ## 脚本做了什�?
95
95
 
96
- 1. 检测 OpenClaw 是否已安装并运行
97
- 2. 安装/升级 `openclaw-xiaoyou` 插件(`openclaw plugins install openclaw-xiaoyou@latest`)
98
- 3. 写入 channel 配置到 `~/.openclaw/openclaw.json`:
96
+ 1. 检�?OpenClaw 是否已安装并运行
97
+ 2. 安装/升级 `openclaw-xiaoyou` 插件(`openclaw plugins install openclaw-xiaoyou@latest`�?
98
+ 3. 写入 channel 配置�?`~/.openclaw/openclaw.json`�?
99
99
  - `channels.xiaoyou.enabled = true`
100
100
  - `channels.xiaoyou.wsUrl = <用户提供的地址>`
101
- - `channels.xiaoyou.authToken = <用户提供的 token>`
101
+ - `channels.xiaoyou.authToken = <用户提供�?token>`
102
102
  - `channels.xiaoyou.dmSecurity = open`
103
- 4. 检查插件状态和 gateway 运行状态
103
+ 4. 检查插件状态和 gateway 运行状�?
104
104
 
105
105
  ## 完成定义
106
106
 
107
- - 脚本退出码为 0
108
- - 日志显示安装、升级或卸载流程完成。
109
- - 安装场景下,`openclaw xiaoyou status` 显示 connected
110
- - 企业服务端能收到来自 xiaoyou 插件的 WebSocket 连接。
107
+ - 脚本退出码�?0�?
108
+ - 日志显示安装、升级或卸载流程完成�?
109
+ - 安装场景下,`openclaw xiaoyou status` 显示 connected�?
110
+ - 企业服务端能收到来自 xiaoyou 插件�?WebSocket 连接�?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-xiaoyou",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "description": "Xiaoyou channel plugin for OpenClaw — connects enterprise services via persistent outbound WebSocket",
6
6
  "openclaw": {
package/src/channel.ts CHANGED
@@ -100,9 +100,8 @@ export const xiayouPlugin = {
100
100
  startAccount: async (ctx: any) => {
101
101
  const { account, cfg, log } = ctx;
102
102
 
103
- // 注入 runtime
104
- if (ctx.runtime) setRuntime(ctx.runtime);
105
-
103
+ // 使用 register 时注入的 runtime(有 channel.reply 等完整 API)
104
+ // 注意:ctx.runtime 只有 log/error/exit,不能用它覆盖
106
105
  const section = account?.config || getChannelConfig(cfg);
107
106
  const logger = log || console;
108
107
 
@@ -128,24 +127,79 @@ export const xiayouPlugin = {
128
127
  account: resolved,
129
128
  logger,
130
129
  onMessage: async (msg) => {
131
- const runtime = getRuntime();
132
- if (!runtime) {
133
- logger.error("[xiaoyou] runtime not available, cannot dispatch");
130
+ const rt = getRuntime();
131
+ if (!rt || !rt.channel) {
132
+ logger.error("[xiaoyou] runtime.channel not available, cannot dispatch");
134
133
  return;
135
134
  }
136
- await runtime.inbound.dispatch({
137
- channelId: "xiaoyou",
138
- senderId: msg.senderId,
139
- senderName: msg.senderName ?? msg.senderId,
140
- conversationId: msg.conversationId,
135
+
136
+ const senderId = msg.senderId;
137
+ const senderName = msg.senderName ?? msg.senderId;
138
+ const conversationId = msg.conversationId;
139
+ const text = msg.text ?? "";
140
+ const accountId = account?.accountId || "default";
141
+
142
+ // 1. 路由
143
+ const route = rt.channel.routing.resolveAgentRoute({
144
+ cfg: getChannelConfig(cfg) || {},
145
+ channel: "xiaoyou",
146
+ accountId,
147
+ peer: { kind: "direct", id: senderId },
148
+ });
149
+
150
+ // 2. 格式化入站消息
151
+ const fromLabel = `${senderName} (${senderId})`;
152
+ const envelopeOptions = rt.channel.reply.resolveEnvelopeFormatOptions(cfg);
153
+ const body = rt.channel.reply.formatInboundEnvelope({
154
+ channel: "Xiaoyou",
155
+ from: fromLabel,
156
+ timestamp: Date.now(),
157
+ body: text,
141
158
  chatType: "direct",
142
- text: msg.text ?? "",
143
- attachments: msg.attachments?.map((a: any) => ({
144
- kind: a.kind,
145
- url: a.url,
146
- mimeType: a.mimeType,
147
- })),
148
- metadata: msg.metadata,
159
+ sender: { name: senderName, id: senderId },
160
+ envelope: envelopeOptions,
161
+ });
162
+
163
+ // 3. 构建上下文
164
+ const inboundCtx = rt.channel.reply.finalizeInboundContext({
165
+ Body: body,
166
+ RawBody: text,
167
+ CommandBody: text,
168
+ From: conversationId,
169
+ To: conversationId,
170
+ SessionKey: route.sessionKey,
171
+ AccountId: accountId,
172
+ ChatType: "direct",
173
+ ConversationLabel: fromLabel,
174
+ SenderName: senderName,
175
+ SenderId: senderId,
176
+ Provider: "xiaoyou",
177
+ Surface: "xiaoyou",
178
+ MessageSid: `xiaoyou-${Date.now()}`,
179
+ Timestamp: Date.now(),
180
+ });
181
+
182
+ // 4. 分发并获取回复
183
+ await rt.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
184
+ ctx: inboundCtx,
185
+ cfg,
186
+ dispatcherOptions: {
187
+ responsePrefix: "",
188
+ deliver: async (payload: any) => {
189
+ const textToSend = payload.markdown || payload.text;
190
+ if (!textToSend) return;
191
+ if (_client && _client.isConnected()) {
192
+ _client.sendReply({
193
+ type: "reply",
194
+ conversationId,
195
+ messageId: `xiaoyou-${Date.now()}`,
196
+ text: textToSend,
197
+ timestamp: Date.now(),
198
+ });
199
+ logger.info(`[xiaoyou] reply sent to ${conversationId}`);
200
+ }
201
+ },
202
+ },
149
203
  });
150
204
  },
151
205
  });