openclaw-sync-assistant 0.0.1 → 0.0.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/README.md +1 -1
- package/index.js +94 -94
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -19,114 +19,114 @@ module.exports = {
|
|
|
19
19
|
console.log("✅ openclaw-sync-assistant 插件已激活!");
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
//
|
|
23
|
-
if (
|
|
24
|
-
context.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
intro(pc.bgCyan(pc.black(" OpenClaw Sync Assistant Setup ")));
|
|
22
|
+
// 在 OpenClaw 插件 API 中注册 CLI 命令
|
|
23
|
+
if (context.registerCommand) {
|
|
24
|
+
context.registerCommand({
|
|
25
|
+
command: "sync.setup",
|
|
26
|
+
description: "Initialize OpenClaw Sync Assistant configuration",
|
|
27
|
+
action: async () => {
|
|
28
|
+
console.log("\n");
|
|
29
|
+
intro(pc.bgCyan(pc.black(" OpenClaw Sync Assistant Setup ")));
|
|
31
30
|
|
|
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
|
-
});
|
|
55
|
-
|
|
56
|
-
let syncSecret = "";
|
|
57
|
-
let githubRepo = "";
|
|
58
|
-
|
|
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
|
-
},
|
|
31
|
+
const syncMethod = await select({
|
|
32
|
+
message: "请选择同步方式 (Sync Method):",
|
|
33
|
+
options: [
|
|
34
|
+
{ value: "p2p", label: "点对点直连 (P2P - 基于 Hyperswarm)" },
|
|
35
|
+
{ value: "github", label: "GitHub 托管 (基于 Git 仓库)" },
|
|
36
|
+
],
|
|
67
37
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
message: "
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
38
|
+
|
|
39
|
+
const syncMode = await select({
|
|
40
|
+
message: "请选择同步模式 (Sync Mode):",
|
|
41
|
+
options: [
|
|
42
|
+
{
|
|
43
|
+
value: "decentralized",
|
|
44
|
+
label:
|
|
45
|
+
"去中心模式 (Decentralized - 适合多设备对等同步,随时随地拉取)",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
value: "centralized",
|
|
49
|
+
label:
|
|
50
|
+
"中心模式 (Centralized - 适合以某台设备或仓库为主的主从同步)",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
75
53
|
});
|
|
76
|
-
}
|
|
77
54
|
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
});
|
|
55
|
+
let syncSecret = "";
|
|
56
|
+
let githubRepo = "";
|
|
88
57
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
58
|
+
if (syncMethod === "p2p") {
|
|
59
|
+
syncSecret = await text({
|
|
60
|
+
message:
|
|
61
|
+
"请输入您的同步密钥 (Sync Secret, 用于生成 P2P 发现的 Topic 和加密数据):",
|
|
62
|
+
placeholder: "例如: my-super-secret-key",
|
|
63
|
+
validate(value) {
|
|
64
|
+
if (value.length === 0) return "同步密钥不能为空!";
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
} else if (syncMethod === "github") {
|
|
68
|
+
githubRepo = await text({
|
|
69
|
+
message: "请输入用于同步的 GitHub 仓库地址:",
|
|
70
|
+
placeholder: "例如: https://github.com/your-name/sync-repo.git",
|
|
71
|
+
validate(value) {
|
|
72
|
+
if (value.length === 0) return "GitHub 仓库地址不能为空!";
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
93
76
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
77
|
+
const syncItems = await multiselect({
|
|
78
|
+
message: "请选择要同步的内容:",
|
|
79
|
+
options: [
|
|
80
|
+
{ value: "Config", label: "Config", hint: "OpenClaw 核心配置" },
|
|
81
|
+
{ value: "Auth", label: "Auth", hint: "认证信息" },
|
|
82
|
+
{ value: "Sessions", label: "Sessions", hint: "会话记录" },
|
|
83
|
+
{ value: "Workspace", label: "Workspace", hint: "工作区状态" },
|
|
84
|
+
],
|
|
85
|
+
required: true,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const s = spinner();
|
|
89
|
+
s.start(
|
|
90
|
+
`正在初始化 [${syncMethod.toUpperCase()} - ${syncMode}] 同步服务...`,
|
|
103
91
|
);
|
|
104
|
-
|
|
92
|
+
|
|
93
|
+
// 模拟保存配置 (实际应使用 context.api.config.update 等方法)
|
|
94
|
+
if (context.api.config && context.api.config.update) {
|
|
105
95
|
await context.api.config.update(
|
|
106
|
-
"openclaw-sync-assistant.
|
|
107
|
-
|
|
96
|
+
"openclaw-sync-assistant.syncMethod",
|
|
97
|
+
syncMethod,
|
|
108
98
|
);
|
|
109
|
-
if (githubRepo)
|
|
110
99
|
await context.api.config.update(
|
|
111
|
-
"openclaw-sync-assistant.
|
|
112
|
-
|
|
100
|
+
"openclaw-sync-assistant.syncMode",
|
|
101
|
+
syncMode,
|
|
113
102
|
);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
}
|
|
119
118
|
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
// 模拟启动相关服务等耗时操作
|
|
120
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
122
121
|
|
|
123
|
-
|
|
122
|
+
s.stop("配置已保存!");
|
|
124
123
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
outro(
|
|
125
|
+
pc.green(
|
|
126
|
+
`✔ 配置完成!同步助手后台服务已按 [${syncMethod.toUpperCase()} - ${syncMode}] 接管状态同步。`,
|
|
127
|
+
),
|
|
128
|
+
);
|
|
129
|
+
},
|
|
130
130
|
});
|
|
131
131
|
} else if (process.env.DEBUG === "openclaw:sync") {
|
|
132
132
|
console.log(
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED