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