openclaw-sync-assistant 0.0.5 → 0.0.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/index.js CHANGED
@@ -18,119 +18,130 @@ module.exports = {
18
18
  console.log("✅ openclaw-sync-assistant 插件已激活!");
19
19
  }
20
20
 
21
- // 安全地注册命令,避免 .trim() 报错
22
- try {
23
- if (
24
- context.api &&
25
- context.api.commands &&
26
- typeof context.api.commands.registerCommand === "function"
27
- ) {
28
- context.api.commands.registerCommand("sync.setup", async () => {
29
- console.log("\n");
30
- intro(pc.bgCyan(pc.black(" OpenClaw Sync Assistant Setup ")));
31
-
32
- const syncMethod = await select({
33
- message: "请选择同步方式 (Sync Method):",
34
- options: [
35
- { value: "p2p", label: "点对点直连 (P2P - 基于 Hyperswarm)" },
36
- { value: "github", label: "GitHub 托管 (基于 Git 仓库)" },
37
- ],
38
- });
39
-
40
- const syncMode = await select({
41
- message: "请选择同步模式 (Sync Mode):",
42
- options: [
43
- {
44
- value: "decentralized",
45
- label:
46
- "去中心模式 (Decentralized - 适合多设备对等同步,随时随地拉取)",
47
- },
48
- {
49
- value: "centralized",
50
- label:
51
- "中心模式 (Centralized - 适合以某台设备或仓库为主的主从同步)",
52
- },
53
- ],
54
- });
21
+ // 根据模式启动后台服务的逻辑占位
22
+ // if (config.syncMethod === 'p2p') startP2PService(context);
23
+ // else if (config.syncMethod === 'github') startGitSyncService(context);
24
+ },
55
25
 
56
- let syncSecret = "";
57
- let githubRepo = "";
26
+ /**
27
+ * 插件命令执行函数 (通过 openclaw.plugin.json 中的 commands 声明触发)
28
+ * @param {string} commandId - 触发的命令 ID
29
+ * @param {object} args - 命令参数
30
+ * @param {object} context - OpenClaw 插件上下文
31
+ */
32
+ async executeCommand(commandId, args, context) {
33
+ if (commandId === "sync.setup") {
34
+ console.log("\n");
35
+ intro(pc.bgCyan(pc.black(" OpenClaw Sync Assistant Setup ")));
58
36
 
59
- if (syncMethod === "p2p") {
60
- syncSecret = await text({
61
- message:
62
- "请输入您的同步密钥 (Sync Secret, 用于生成 P2P 发现的 Topic 和加密数据):",
63
- placeholder: "例如: my-super-secret-key",
64
- validate(value) {
65
- if (value.length === 0) return "同步密钥不能为空!";
66
- },
67
- });
68
- } else if (syncMethod === "github") {
69
- githubRepo = await text({
70
- message: "请输入用于同步的 GitHub 仓库地址:",
71
- placeholder: "例如: https://github.com/your-name/sync-repo.git",
72
- validate(value) {
73
- if (value.length === 0) return "GitHub 仓库地址不能为空!";
74
- },
75
- });
76
- }
37
+ const syncMethod = await select({
38
+ message: "请选择同步方式 (Sync Method):",
39
+ options: [
40
+ { value: "p2p", label: "点对点直连 (P2P - 基于 Hyperswarm)" },
41
+ { value: "github", label: "GitHub 托管 (基于 Git 仓库)" },
42
+ ],
43
+ });
77
44
 
78
- const syncItems = await multiselect({
79
- message: "请选择要同步的内容:",
80
- options: [
81
- { value: "Config", label: "Config", hint: "OpenClaw 核心配置" },
82
- { value: "Auth", label: "Auth", hint: "认证信息" },
83
- { value: "Sessions", label: "Sessions", hint: "会话记录" },
84
- { value: "Workspace", label: "Workspace", hint: "工作区状态" },
85
- ],
86
- required: true,
87
- });
45
+ const syncMode = await select({
46
+ message: "请选择同步模式 (Sync Mode):",
47
+ options: [
48
+ {
49
+ value: "decentralized",
50
+ label:
51
+ "去中心模式 (Decentralized - 适合多设备对等同步,随时随地拉取)",
52
+ },
53
+ {
54
+ value: "centralized",
55
+ label:
56
+ "中心模式 (Centralized - 适合以某台设备或仓库为主的主从同步)",
57
+ },
58
+ ],
59
+ });
88
60
 
89
- const s = spinner();
90
- s.start(
91
- `正在初始化 [${syncMethod.toUpperCase()} - ${syncMode}] 同步服务...`,
92
- );
61
+ let syncSecret = "";
62
+ let githubRepo = "";
93
63
 
94
- if (context.api.config && context.api.config.update) {
95
- await context.api.config.update(
96
- "openclaw-sync-assistant.syncMethod",
97
- syncMethod,
98
- );
99
- await context.api.config.update(
100
- "openclaw-sync-assistant.syncMode",
101
- syncMode,
102
- );
103
- if (syncSecret)
104
- await context.api.config.update(
105
- "openclaw-sync-assistant.syncSecret",
106
- syncSecret,
107
- );
108
- if (githubRepo)
109
- await context.api.config.update(
110
- "openclaw-sync-assistant.githubRepo",
111
- githubRepo,
112
- );
113
- await context.api.config.update(
114
- "openclaw-sync-assistant.syncItems",
115
- syncItems,
116
- );
117
- }
64
+ if (syncMethod === "p2p") {
65
+ syncSecret = await text({
66
+ message:
67
+ "请输入您的同步密钥 (Sync Secret, 用于生成 P2P 发现的 Topic 和加密数据):",
68
+ placeholder: "例如: my-super-secret-key",
69
+ validate(value) {
70
+ if (value.length === 0) return "同步密钥不能为空!";
71
+ },
72
+ });
73
+ } else if (syncMethod === "github") {
74
+ githubRepo = await text({
75
+ message: "请输入用于同步的 GitHub 仓库地址:",
76
+ placeholder: "例如: https://github.com/your-name/sync-repo.git",
77
+ validate(value) {
78
+ if (value.length === 0) return "GitHub 仓库地址不能为空!";
79
+ },
80
+ });
81
+ }
118
82
 
119
- await new Promise((resolve) => setTimeout(resolve, 1500));
83
+ const syncItems = await multiselect({
84
+ message: "请选择要同步的内容:",
85
+ options: [
86
+ { value: "Config", label: "Config", hint: "OpenClaw 核心配置" },
87
+ { value: "Auth", label: "Auth", hint: "认证信息" },
88
+ { value: "Sessions", label: "Sessions", hint: "会话记录" },
89
+ { value: "Workspace", label: "Workspace", hint: "工作区状态" },
90
+ ],
91
+ required: true,
92
+ });
120
93
 
121
- s.stop("配置已保存!");
94
+ const s = spinner();
95
+ s.start(
96
+ `正在初始化 [${syncMethod.toUpperCase()} - ${syncMode}] 同步服务...`,
97
+ );
122
98
 
123
- outro(
124
- pc.green(
125
- `✔ 配置完成!同步助手后台服务已按 [${syncMethod.toUpperCase()} - ${syncMode}] 接管状态同步。`,
126
- ),
99
+ // 如果通过 executeCommand 传入的 context 带有 api,则更新配置
100
+ if (
101
+ context &&
102
+ context.api &&
103
+ context.api.config &&
104
+ context.api.config.update
105
+ ) {
106
+ await context.api.config.update(
107
+ "openclaw-sync-assistant.syncMethod",
108
+ syncMethod,
109
+ );
110
+ await context.api.config.update(
111
+ "openclaw-sync-assistant.syncMode",
112
+ syncMode,
113
+ );
114
+ if (syncSecret)
115
+ await context.api.config.update(
116
+ "openclaw-sync-assistant.syncSecret",
117
+ syncSecret,
127
118
  );
128
- });
129
- }
130
- } catch (e) {
131
- if (process.env.DEBUG === "openclaw:sync") {
132
- console.error("❌ 注册命令失败:", e);
119
+ if (githubRepo)
120
+ await context.api.config.update(
121
+ "openclaw-sync-assistant.githubRepo",
122
+ githubRepo,
123
+ );
124
+ await context.api.config.update(
125
+ "openclaw-sync-assistant.syncItems",
126
+ syncItems,
127
+ );
128
+ } else {
129
+ if (process.env.DEBUG === "openclaw:sync") {
130
+ console.log(
131
+ "提示: 未找到 context.api.config.update,配置未持久化保存。",
132
+ );
133
+ }
133
134
  }
135
+
136
+ await new Promise((resolve) => setTimeout(resolve, 1500));
137
+
138
+ s.stop("配置已保存!");
139
+
140
+ outro(
141
+ pc.green(
142
+ `✔ 配置完成!同步助手后台服务已按 [${syncMethod.toUpperCase()} - ${syncMode}] 接管状态同步。`,
143
+ ),
144
+ );
134
145
  }
135
146
  },
136
147
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "openclaw-sync-assistant",
3
3
  "name": "openclaw-sync-assistant",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "description": "OpenClaw Sync Assistant Plugin",
6
6
  "commands": [
7
7
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-sync-assistant",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "An OpenClaw plugin for P2P file and data synchronization using Hyperswarm and Hyperdrive ecosystem.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",