@privateclaw/privateclaw 0.1.25 → 0.1.27
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 +33 -5
- package/dist/bot-mode-topics.d.ts +7 -0
- package/dist/bot-mode-topics.js +236 -0
- package/dist/bot-mode-topics.js.map +1 -0
- package/dist/bridges/openclaw-agent-bridge.js +10 -2
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/cli.js +69 -6
- package/dist/cli.js.map +1 -1
- package/dist/provider.d.ts +4 -1
- package/dist/provider.js +328 -218
- package/dist/provider.js.map +1 -1
- package/dist/setup.d.ts +86 -0
- package/dist/setup.js +501 -0
- package/dist/setup.js.map +1 -0
- package/dist/text.d.ts +3 -0
- package/dist/text.js +3 -0
- package/dist/text.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/bot-mode-topics.test.ts +39 -0
- package/src/bot-mode-topics.ts +248 -0
- package/src/bridges/openclaw-agent-bridge.test.ts +59 -0
- package/src/bridges/openclaw-agent-bridge.ts +11 -2
- package/src/cli.ts +92 -4
- package/src/provider.test.ts +489 -1
- package/src/provider.ts +451 -271
- package/src/setup.test.ts +187 -0
- package/src/setup.ts +814 -0
- package/src/text.ts +16 -0
- package/src/types.ts +2 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
buildPrivateClawSetupPlan,
|
|
5
|
+
detectLocalOpenClawStatus,
|
|
6
|
+
EFFECTIVELY_PERMANENT_SESSION_TTL_MS,
|
|
7
|
+
parsePrivateClawSessionDurationPreset,
|
|
8
|
+
renderPrivateClawSetupGuidance,
|
|
9
|
+
resolvePrivateClawSetupSelection,
|
|
10
|
+
runPrivateClawSetup,
|
|
11
|
+
} from "./setup.js";
|
|
12
|
+
|
|
13
|
+
test("detectLocalOpenClawStatus falls back to the privateclaw help probe when commands list is unavailable", async () => {
|
|
14
|
+
const status = await detectLocalOpenClawStatus(async (_command, args) => {
|
|
15
|
+
if (args.length === 1 && args[0] === "--version") {
|
|
16
|
+
return {
|
|
17
|
+
stdout: "OpenClaw 2026.3.22\n",
|
|
18
|
+
stderr: "",
|
|
19
|
+
combined: "OpenClaw 2026.3.22\n",
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (args[0] === "commands" && args[1] === "list") {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"Command `openclaw commands list` exited with code 1: error: unknown command 'commands'",
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (
|
|
28
|
+
args[0] === "privateclaw" &&
|
|
29
|
+
args[1] === "pair" &&
|
|
30
|
+
args[2] === "--help"
|
|
31
|
+
) {
|
|
32
|
+
return {
|
|
33
|
+
stdout: "Usage: openclaw privateclaw pair [options]\n",
|
|
34
|
+
stderr: "",
|
|
35
|
+
combined: "Usage: openclaw privateclaw pair [options]\n",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (args[0] === "plugins" && args[1] === "info" && args[2] === "privateclaw") {
|
|
39
|
+
throw new Error("Plugin not found");
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Unexpected command args: ${args.join(" ")}`);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
assert.deepEqual(status, {
|
|
45
|
+
openClawAvailable: true,
|
|
46
|
+
privateClawCommandAvailable: true,
|
|
47
|
+
privateClawPluginPresent: false,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("parsePrivateClawSessionDurationPreset supports the permanent preset", () => {
|
|
52
|
+
const preset = parsePrivateClawSessionDurationPreset("permanent");
|
|
53
|
+
assert.equal(preset.ttlMs, EFFECTIVELY_PERMANENT_SESSION_TTL_MS);
|
|
54
|
+
assert.match(preset.label, /Permanent/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("resolvePrivateClawSetupSelection prompts for missing mode and duration", async () => {
|
|
58
|
+
const prompts: string[] = [];
|
|
59
|
+
const selection = await resolvePrivateClawSetupSelection({
|
|
60
|
+
promptForChoice: async (question, _choices, defaultValue) => {
|
|
61
|
+
prompts.push(question);
|
|
62
|
+
if (question.includes("session type")) {
|
|
63
|
+
return "group";
|
|
64
|
+
}
|
|
65
|
+
assert.equal(defaultValue, "24h");
|
|
66
|
+
return "1w";
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
assert.equal(selection.groupMode, true);
|
|
71
|
+
assert.equal(selection.ttlMs, 7 * 24 * 60 * 60 * 1000);
|
|
72
|
+
assert.match(selection.durationLabel, /1 week/);
|
|
73
|
+
assert.equal(prompts.length, 2);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("buildPrivateClawSetupPlan prints manual OpenClaw commands when openclaw is unavailable", () => {
|
|
77
|
+
const plan = buildPrivateClawSetupPlan({
|
|
78
|
+
packageSpec: "@privateclaw/privateclaw@0.1.26",
|
|
79
|
+
status: {
|
|
80
|
+
openClawAvailable: false,
|
|
81
|
+
privateClawCommandAvailable: false,
|
|
82
|
+
},
|
|
83
|
+
selection: {
|
|
84
|
+
groupMode: true,
|
|
85
|
+
ttlMs: 2 * 60 * 60 * 1000,
|
|
86
|
+
durationLabel: "2 小时 / 2 hours",
|
|
87
|
+
},
|
|
88
|
+
relayBaseUrl: "https://relay.example.com",
|
|
89
|
+
label: "hello",
|
|
90
|
+
openInBrowser: true,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
assert.equal(plan.localOpenClaw, false);
|
|
94
|
+
assert.equal(plan.manualSteps.length, 4);
|
|
95
|
+
assert.match(
|
|
96
|
+
renderPrivateClawSetupGuidance(plan),
|
|
97
|
+
/openclaw plugins install @privateclaw\/privateclaw@0\.1\.26/,
|
|
98
|
+
);
|
|
99
|
+
assert.equal(
|
|
100
|
+
plan.pairingCommand.display,
|
|
101
|
+
"openclaw privateclaw pair --ttl-ms 7200000 --group --label hello --relay https://relay.example.com --open",
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("runPrivateClawSetup installs, enables, restarts, then starts pairing", async () => {
|
|
106
|
+
const executed: string[] = [];
|
|
107
|
+
const pairings: string[] = [];
|
|
108
|
+
const logs: string[] = [];
|
|
109
|
+
let detectCalls = 0;
|
|
110
|
+
|
|
111
|
+
await runPrivateClawSetup({
|
|
112
|
+
packageSpec: "@privateclaw/privateclaw@0.1.26",
|
|
113
|
+
selection: {
|
|
114
|
+
groupMode: true,
|
|
115
|
+
ttlMs: 8 * 60 * 60 * 1000,
|
|
116
|
+
durationLabel: "8 小时 / 8 hours",
|
|
117
|
+
},
|
|
118
|
+
relayBaseUrl: "https://relay.example.com",
|
|
119
|
+
label: "demo",
|
|
120
|
+
verbose: true,
|
|
121
|
+
onLog: (line) => {
|
|
122
|
+
logs.push(line);
|
|
123
|
+
},
|
|
124
|
+
detectLocalOpenClawStatus: async () => {
|
|
125
|
+
detectCalls += 1;
|
|
126
|
+
if (detectCalls === 1) {
|
|
127
|
+
return {
|
|
128
|
+
openClawAvailable: true,
|
|
129
|
+
privateClawCommandAvailable: false,
|
|
130
|
+
privateClawPluginPresent: false,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
openClawAvailable: true,
|
|
135
|
+
privateClawCommandAvailable: true,
|
|
136
|
+
privateClawPluginPresent: true,
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
runStep: async (step) => {
|
|
140
|
+
executed.push(step.display);
|
|
141
|
+
},
|
|
142
|
+
runPairingCommand: async (step) => {
|
|
143
|
+
pairings.push(step.display);
|
|
144
|
+
return {
|
|
145
|
+
stdout: "",
|
|
146
|
+
stderr: "",
|
|
147
|
+
combined: "",
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
verificationTimeoutMs: 10,
|
|
151
|
+
verificationPollMs: 0,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
assert.deepEqual(executed, [
|
|
155
|
+
"openclaw plugins install @privateclaw/privateclaw@0.1.26",
|
|
156
|
+
"openclaw plugins enable privateclaw",
|
|
157
|
+
"openclaw gateway restart",
|
|
158
|
+
]);
|
|
159
|
+
assert.deepEqual(pairings, [
|
|
160
|
+
"openclaw privateclaw pair --ttl-ms 28800000 --group --label demo --relay https://relay.example.com --verbose",
|
|
161
|
+
]);
|
|
162
|
+
assert.match(logs.join("\n"), /Verified command availability/);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("runPrivateClawSetup prints guidance and fails when openclaw is unavailable locally", async () => {
|
|
166
|
+
const logs: string[] = [];
|
|
167
|
+
|
|
168
|
+
await assert.rejects(
|
|
169
|
+
runPrivateClawSetup({
|
|
170
|
+
selection: {
|
|
171
|
+
groupMode: false,
|
|
172
|
+
ttlMs: 30 * 60 * 1000,
|
|
173
|
+
durationLabel: "30 分钟 / 30 minutes",
|
|
174
|
+
},
|
|
175
|
+
onLog: (line) => {
|
|
176
|
+
logs.push(line);
|
|
177
|
+
},
|
|
178
|
+
detectLocalOpenClawStatus: async () => ({
|
|
179
|
+
openClawAvailable: false,
|
|
180
|
+
privateClawCommandAvailable: false,
|
|
181
|
+
}),
|
|
182
|
+
}),
|
|
183
|
+
/cannot be installed automatically/i,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
assert.match(logs.join("\n"), /Run these commands on the machine where OpenClaw is installed/i);
|
|
187
|
+
});
|