openclaw-xiaoyou 1.0.6 → 1.1.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/channel.ts +45 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-xiaoyou",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
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
@@ -21,12 +21,21 @@ export function getRuntime() { return _runtime; }
21
21
 
22
22
  // ─── Config Adapter ──────────────────────────────────
23
23
 
24
- function resolveAccount(cfg: any): ResolvedAccount {
25
- const section = cfg.channels?.["xiaoyou"] ?? cfg;
26
- if (!section.wsUrl) throw new Error("xiaoyou: wsUrl is required");
24
+ function getChannelConfig(cfg: any): any {
25
+ return cfg?.channels?.xiaoyou ?? {};
26
+ }
27
+
28
+ function resolveAccount(cfg: any, accountId?: string | null): any {
29
+ const section = getChannelConfig(cfg);
30
+ const id = accountId || "default";
31
+ const configured = Boolean(section.wsUrl);
27
32
 
28
33
  return {
29
- wsUrl: section.wsUrl,
34
+ accountId: id,
35
+ config: section,
36
+ enabled: section.enabled !== false,
37
+ configured,
38
+ wsUrl: section.wsUrl ?? "",
30
39
  authToken: section.authToken ?? "",
31
40
  allowFrom: section.allowFrom ?? [],
32
41
  dmPolicy: section.dmSecurity,
@@ -38,7 +47,7 @@ function resolveAccount(cfg: any): ResolvedAccount {
38
47
  }
39
48
 
40
49
  function inspectAccount(cfg: any) {
41
- const section = cfg.channels?.["xiaoyou"] ?? cfg;
50
+ const section = getChannelConfig(cfg);
42
51
  return {
43
52
  enabled: Boolean(section?.wsUrl),
44
53
  configured: Boolean(section?.wsUrl),
@@ -47,7 +56,7 @@ function inspectAccount(cfg: any) {
47
56
  }
48
57
 
49
58
  function listAccountIds(cfg: any): string[] {
50
- const section = cfg.channels?.["xiaoyou"] ?? cfg;
59
+ const section = getChannelConfig(cfg);
51
60
  if (section?.wsUrl) return ["default"];
52
61
  return [];
53
62
  }
@@ -85,6 +94,13 @@ export const xiayouPlugin = {
85
94
  resolveAccount,
86
95
  inspectAccount,
87
96
  listAccountIds,
97
+ isConfigured: (account: any): boolean => Boolean(account?.config?.wsUrl),
98
+ describeAccount: (account: any) => ({
99
+ accountId: account?.accountId || "default",
100
+ name: "Xiaoyou",
101
+ enabled: account?.enabled !== false,
102
+ }),
103
+ defaultAccountId: (): string => "default",
88
104
  },
89
105
 
90
106
  // ── DM 安全策略 ────────────────────────────────────
@@ -101,12 +117,24 @@ export const xiayouPlugin = {
101
117
  threading: { topLevelReplyToMode: "reply" as const },
102
118
 
103
119
  // ── Gateway 生命周期 ───────────────────────────────
120
+ reload: { configPrefixes: ["channels.xiaoyou"] },
121
+
104
122
  gateway: {
105
- start: async ({ account, config, logger }: any) => {
106
- const resolved: ResolvedAccount =
107
- typeof account.wsUrl === "string"
108
- ? account
109
- : resolveAccount(config);
123
+ startAccount: async (ctx: any) => {
124
+ const { account, cfg, log } = ctx;
125
+ const section = account?.config || getChannelConfig(cfg);
126
+ const logger = log || console;
127
+
128
+ const resolved: ResolvedAccount = {
129
+ wsUrl: section?.wsUrl ?? "",
130
+ authToken: section?.authToken ?? "",
131
+ allowFrom: section?.allowFrom ?? [],
132
+ dmPolicy: section?.dmSecurity,
133
+ reconnectIntervalMs: section?.reconnectIntervalMs ?? 3000,
134
+ maxReconnectAttempts: section?.maxReconnectAttempts ?? 0,
135
+ heartbeatIntervalMs: section?.heartbeatIntervalMs ?? 30000,
136
+ heartbeatTimeoutMs: section?.heartbeatTimeoutMs ?? 10000,
137
+ };
110
138
 
111
139
  // 断开已有连接
112
140
  if (_client) _client.disconnect();
@@ -143,9 +171,8 @@ export const xiayouPlugin = {
143
171
  return client;
144
172
  },
145
173
 
146
- stop: async (client: EnterpriseClient) => {
147
- client.disconnect();
148
- if (_client === client) _client = null;
174
+ stopAccount: async () => {
175
+ if (_client) { _client.disconnect(); _client = null; }
149
176
  },
150
177
  },
151
178
 
@@ -184,9 +211,11 @@ export const xiayouPlugin = {
184
211
  status: {
185
212
  describe: async ({ account }: any) => {
186
213
  const issues: Array<{ severity: string; message: string }> = [];
214
+ const wsUrl = account?.wsUrl ?? account?.config?.wsUrl;
215
+ const authToken = account?.authToken ?? account?.config?.authToken;
187
216
 
188
- if (!account?.wsUrl) issues.push({ severity: "error", message: "wsUrl not configured" });
189
- if (!account?.authToken) issues.push({ severity: "warning", message: "authToken not set" });
217
+ if (!wsUrl) issues.push({ severity: "error", message: "wsUrl not configured" });
218
+ if (!authToken) issues.push({ severity: "warning", message: "authToken not set" });
190
219
  if (!_client || !_client.isConnected()) issues.push({ severity: "error", message: "WebSocket not connected" });
191
220
 
192
221
  return {