@honor-claw/yoyo 0.0.1-alpha.2 → 0.0.1-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honor-claw/yoyo",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-beta.3",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Honor Yoyo connection plugin",
6
6
  "scripts": {
@@ -2,11 +2,11 @@
2
2
  * 配置管理器 - 统一管理 openclaw 配置文件的读写
3
3
  */
4
4
 
5
- import type { OpenClawConfig } from 'openclaw/plugin-sdk';
6
- import { getYoyoRuntime } from '../../runtime.js';
7
- import type { GatewayAuthConfig, UserConfig } from './types.js';
5
+ import type { OpenClawConfig } from "openclaw/plugin-sdk";
6
+ import { getYoyoRuntime } from "../../runtime.js";
7
+ import type { GatewayAuthConfig, UserConfig } from "./types.js";
8
8
 
9
- const PLUGIN_YOYO_ID = 'yoyo';
9
+ const PLUGIN_YOYO_ID = "yoyo";
10
10
 
11
11
  /**
12
12
  * 配置管理器类
@@ -20,7 +20,11 @@ export class ConfigManager {
20
20
  const runtime = getYoyoRuntime();
21
21
  return runtime.config.loadConfig();
22
22
  } catch (error) {
23
- throw new Error(`加载配置失败: ${error instanceof Error ? error.message : String(error)}`);
23
+ throw new Error(
24
+ `Failed to load config: ${
25
+ error instanceof Error ? error.message : String(error)
26
+ }`
27
+ );
24
28
  }
25
29
  }
26
30
 
@@ -32,7 +36,11 @@ export class ConfigManager {
32
36
  const runtime = getYoyoRuntime();
33
37
  await runtime.config.writeConfigFile(config);
34
38
  } catch (error) {
35
- throw new Error(`保存配置失败: ${error instanceof Error ? error.message : String(error)}`);
39
+ throw new Error(
40
+ `Failed to save config: ${
41
+ error instanceof Error ? error.message : String(error)
42
+ }`
43
+ );
36
44
  }
37
45
  }
38
46
 
@@ -65,7 +73,9 @@ export class ConfigManager {
65
73
 
66
74
  return result;
67
75
  } catch (error) {
68
- console.error(`[claw-configs] Failed to read gateway auth config: ${error}`);
76
+ console.error(
77
+ `[claw-configs] Failed to read gateway auth config: ${error}`
78
+ );
69
79
  return undefined;
70
80
  }
71
81
  }
@@ -79,7 +89,9 @@ export class ConfigManager {
79
89
  const port = config.gateway?.port;
80
90
  return port ?? 18789;
81
91
  } catch (error) {
82
- console.error(`[claw-configs] Failed to read gateway port config: ${error}`);
92
+ console.error(
93
+ `[claw-configs] Failed to read gateway port config: ${error}`
94
+ );
83
95
  return 18789;
84
96
  }
85
97
  }
@@ -90,7 +102,8 @@ export class ConfigManager {
90
102
  getUserConfig(): UserConfig | undefined {
91
103
  try {
92
104
  const config = this.loadConfig();
93
- const userConfig = config.plugins?.entries?.[PLUGIN_YOYO_ID]?.config?.user as UserConfig | undefined;
105
+ const userConfig = config.plugins?.entries?.[PLUGIN_YOYO_ID]?.config
106
+ ?.user as UserConfig | undefined;
94
107
  return userConfig;
95
108
  } catch (error) {
96
109
  console.error(`[claw-configs] Failed to read user config: ${error}`);
@@ -124,7 +137,11 @@ export class ConfigManager {
124
137
 
125
138
  await this.saveConfig(updatedConfig);
126
139
  } catch (error) {
127
- throw new Error(`更新用户配置失败: ${error instanceof Error ? error.message : String(error)}`);
140
+ throw new Error(
141
+ `Failed to update user config: ${
142
+ error instanceof Error ? error.message : String(error)
143
+ }`
144
+ );
128
145
  }
129
146
  }
130
147
 
@@ -153,7 +170,79 @@ export class ConfigManager {
153
170
 
154
171
  await this.saveConfig(updatedConfig);
155
172
  } catch (error) {
156
- throw new Error(`清除用户配置失败: ${error instanceof Error ? error.message : String(error)}`);
173
+ throw new Error(
174
+ `Failed to clear user config: ${
175
+ error instanceof Error ? error.message : String(error)
176
+ }`
177
+ );
178
+ }
179
+ }
180
+
181
+ /**
182
+ * 初始化插件配置 - 统一处理插件和命令配置
183
+ */
184
+ async initializePluginConfig(pluginId: string): Promise<void> {
185
+ try {
186
+ const currentConfig = this.loadConfig();
187
+
188
+ // 处理 plugins.allow
189
+ const currentAllow = currentConfig.plugins?.allow || [];
190
+ const updatedAllow = currentAllow.includes(pluginId)
191
+ ? currentAllow
192
+ : [...currentAllow, pluginId];
193
+
194
+ // 处理 gateway.nodes.allowCommands
195
+ const commandsToAdd = [
196
+ "phone.call",
197
+ "volume.operate",
198
+ "capture.shot",
199
+ "app.open",
200
+ "record.screen",
201
+ "message.send",
202
+ "local.search",
203
+ "send.message",
204
+ "search.record",
205
+ "search.message",
206
+ "alarm.create",
207
+ "schedule.create",
208
+ "search.contact",
209
+ "alarm.delete",
210
+ "alarm.enable",
211
+ "alarm.disable",
212
+ "schedule.update",
213
+ "schedule.delete",
214
+ "schedule.search",
215
+ ];
216
+
217
+ const currentAllowCommands =
218
+ currentConfig.gateway?.nodes?.allowCommands || [];
219
+ const mergedCommands = Array.from(
220
+ new Set([...currentAllowCommands, ...commandsToAdd])
221
+ );
222
+
223
+ // 一次性更新所有配置
224
+ const updatedConfig: OpenClawConfig = {
225
+ ...currentConfig,
226
+ plugins: {
227
+ ...currentConfig.plugins,
228
+ allow: updatedAllow,
229
+ },
230
+ gateway: {
231
+ ...currentConfig.gateway,
232
+ nodes: {
233
+ ...currentConfig.gateway?.nodes,
234
+ allowCommands: mergedCommands,
235
+ },
236
+ },
237
+ };
238
+
239
+ await this.saveConfig(updatedConfig);
240
+ } catch (error) {
241
+ throw new Error(
242
+ `failed to initialize plugin config: ${
243
+ error instanceof Error ? error.message : String(error)
244
+ }`
245
+ );
157
246
  }
158
247
  }
159
248
  }
@@ -5,6 +5,7 @@ import { ClawConnection, type ConnectionStatus } from "./types.js";
5
5
  import { loadToken, clearToken } from "../../honor-auth/token-manager.js";
6
6
  import { getDeviceInfo, registerDevice } from "../../modules/device/index.js";
7
7
  import { DeviceInfo, HonorUserInfo } from "../../types.js";
8
+ import { getConfigManager } from "../../modules/claw-configs/config-manager.js";
8
9
 
9
10
  const clawConnection: ClawConnection = {
10
11
  channel: null,
@@ -26,6 +27,17 @@ export const ClawConnectionService: OpenClawPluginService = {
26
27
 
27
28
  // 启动轮询机制
28
29
  startPolling();
30
+
31
+ // 修改配置文件,配置`plugins.allow`和`gateway.nodes.allowCommands`
32
+ try {
33
+ const configManager = getConfigManager();
34
+ await configManager.initializePluginConfig("yoyo");
35
+ useClawLogger().info("[yoyoclaw] plugin config initialized");
36
+ } catch (error) {
37
+ useClawLogger().error(
38
+ `[yoyoclaw] failed to initialize plugin config: ${String(error)}`
39
+ );
40
+ }
29
41
  },
30
42
  stop(_ctx) {
31
43
  useClawLogger().info("[yoyoclaw-conn] stopping connection service");