@privateclaw/privateclaw 0.1.12 → 0.1.13
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 +16 -3
- package/dist/cli.js +30 -8
- package/dist/cli.js.map +1 -1
- package/dist/openclaw-plugin.js +136 -22
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/text.d.ts +1 -0
- package/dist/text.js +2 -1
- package/dist/text.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +36 -8
- package/src/openclaw-plugin.test.ts +192 -0
- package/src/openclaw-plugin.ts +224 -51
- package/src/text.ts +7 -2
package/dist/text.js
CHANGED
|
@@ -11,13 +11,14 @@ export function buildInviteAnnouncementText(params) {
|
|
|
11
11
|
return formatBilingualText(`PrivateClaw 会话 ${params.sessionId} 已就绪,有效期至 ${params.expiresAt}。请使用 PrivateClaw App 扫描二维码,或粘贴邀请链接完成连接。`, `PrivateClaw session ${params.sessionId} is ready until ${params.expiresAt}. Scan the QR code or paste the invite link into the PrivateClaw app to connect.`);
|
|
12
12
|
}
|
|
13
13
|
export const PRIVATECLAW_PLUGIN_DESCRIPTION = formatBilingualInline("OpenClaw 的一次性端到端加密 PrivateClaw 会话插件。", "Ephemeral end-to-end encrypted PrivateClaw session plugin for OpenClaw.");
|
|
14
|
-
export const PRIVATECLAW_COMMAND_DESCRIPTION = formatBilingualInline("创建一次性加密的 PrivateClaw 会话二维码;传入 `group`
|
|
14
|
+
export const PRIVATECLAW_COMMAND_DESCRIPTION = formatBilingualInline("创建一次性加密的 PrivateClaw 会话二维码;传入 `group` 可启用群聊模式,传入 `relay=<url>` 或 `--relay <url>` 可临时覆盖 relay。", "Create a one-time encrypted PrivateClaw session QR code; pass `group` to enable group chat, and `relay=<url>` or `--relay <url>` to override the relay for this invite.");
|
|
15
15
|
export const PRIVATECLAW_CLI_ROOT_DESCRIPTION = formatBilingualInline("PrivateClaw 本地配对与会话工具。", "PrivateClaw local pairing and session utilities.");
|
|
16
16
|
export const PRIVATECLAW_CLI_PAIR_DESCRIPTION = formatBilingualInline("启动本地 PrivateClaw 会话,并在终端中渲染配对二维码。", "Start a local PrivateClaw session and render the pairing QR code in the terminal.");
|
|
17
17
|
export const PRIVATECLAW_CLI_SESSIONS_DESCRIPTION = formatBilingualInline("列出当前活动中的 PrivateClaw 会话及参与者。", "List the active PrivateClaw sessions and their participants.");
|
|
18
18
|
export const PRIVATECLAW_CLI_KICK_DESCRIPTION = formatBilingualInline("从群聊会话中移除指定参与者。", "Remove a participant from a group session.");
|
|
19
19
|
export const PRIVATECLAW_CLI_TTL_OPTION_DESCRIPTION = formatBilingualInline("会话 TTL(毫秒)。", "Session TTL in milliseconds.");
|
|
20
20
|
export const PRIVATECLAW_CLI_LABEL_OPTION_DESCRIPTION = formatBilingualInline("可选的中继会话标签。", "Optional relay session label.");
|
|
21
|
+
export const PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION = formatBilingualInline("临时覆盖本次命令使用的 relay base URL。", "Temporarily override the relay base URL for this command.");
|
|
21
22
|
export const PRIVATECLAW_CLI_GROUP_OPTION_DESCRIPTION = formatBilingualInline("允许多个 PrivateClaw 客户端加入同一个会话。", "Allow multiple PrivateClaw app clients to join the same session.");
|
|
22
23
|
export const PRIVATECLAW_CLI_PRINT_ONLY_OPTION_DESCRIPTION = formatBilingualInline("仅打印邀请信息和二维码,然后立即退出。", "Print the invite and QR code, then exit immediately.");
|
|
23
24
|
export const PRIVATECLAW_CLI_OPEN_OPTION_DESCRIPTION = formatBilingualInline("生成二维码后在浏览器中打开本地预览页。", "Open a local browser preview after generating the QR code.");
|
package/dist/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,OAAe,EAAE,OAAe;IAClE,OAAO,GAAG,OAAO,KAAK,OAAO,EAAE,CAAC;AAClC,CAAC;AAED,MAAM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,kCAAkC,GAAG,qBAAqB,CACrE,kBAAkB,EAClB,wCAAwC,CACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privateclaw/privateclaw",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "PrivateClaw provider runtime and OpenClaw-compatible plugin adapter",
|
|
3
|
+
"version": "0.1.13",
|
|
4
|
+
"description": "PrivateClaw provider runtime and OpenClaw-compatible plugin adapter. iOS public beta: https://testflight.apple.com/join/XvgJ9c33 ; Android closed alpha requires joining https://groups.google.com/g/gg-studio-ai-products before installing https://play.google.com/store/apps/details?id=gg.ai.privateclaw",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
package/src/cli.ts
CHANGED
|
@@ -27,7 +27,10 @@ import {
|
|
|
27
27
|
PrivateClawSessionControlServer,
|
|
28
28
|
resolvePrivateClawStateDir,
|
|
29
29
|
} from "./session-control.js";
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
formatBilingualInline,
|
|
32
|
+
PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION,
|
|
33
|
+
} from "./text.js";
|
|
31
34
|
import type { PrivateClawProviderHandoffState } from "./types.js";
|
|
32
35
|
|
|
33
36
|
type BridgeMode =
|
|
@@ -94,6 +97,7 @@ function detectBridgeMode(): BridgeMode {
|
|
|
94
97
|
|
|
95
98
|
function createProvider(params?: {
|
|
96
99
|
providerId?: string;
|
|
100
|
+
relayBaseUrl?: string;
|
|
97
101
|
}): {
|
|
98
102
|
provider: PrivateClawProvider;
|
|
99
103
|
stateDir: string;
|
|
@@ -101,9 +105,11 @@ function createProvider(params?: {
|
|
|
101
105
|
const providerWsUrl = process.env.PRIVATECLAW_PROVIDER_WS_URL?.trim();
|
|
102
106
|
const appWsUrl = process.env.PRIVATECLAW_APP_WS_URL?.trim();
|
|
103
107
|
const relayBaseUrl =
|
|
104
|
-
|
|
108
|
+
params?.relayBaseUrl?.trim() ||
|
|
109
|
+
process.env.PRIVATECLAW_RELAY_BASE_URL?.trim() ||
|
|
110
|
+
DEFAULT_RELAY_BASE_URL;
|
|
105
111
|
const relayEndpoints =
|
|
106
|
-
providerWsUrl && appWsUrl
|
|
112
|
+
!params?.relayBaseUrl && providerWsUrl && appWsUrl
|
|
107
113
|
? { providerWsUrl, appWsUrl }
|
|
108
114
|
: resolveRelayEndpoints(relayBaseUrl);
|
|
109
115
|
const bridgeMode = detectBridgeMode();
|
|
@@ -236,9 +242,10 @@ async function readHandoffState(
|
|
|
236
242
|
function printHelp(): void {
|
|
237
243
|
console.log(`privateclaw-provider <pair|sessions|kick>
|
|
238
244
|
|
|
239
|
-
pair [--ttl-ms <ms>] [--label <label>] [--group] [--print-only] [--open] [--foreground]
|
|
245
|
+
pair [--ttl-ms <ms>] [--label <label>] [--relay <url>] [--group] [--print-only] [--open] [--foreground]
|
|
240
246
|
sessions
|
|
241
247
|
kick <sessionId> <appId>`);
|
|
248
|
+
console.log(`\n--relay <url>: ${PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION}`);
|
|
242
249
|
}
|
|
243
250
|
|
|
244
251
|
async function runPairCommand(args: string[]): Promise<void> {
|
|
@@ -248,6 +255,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
248
255
|
options: {
|
|
249
256
|
"ttl-ms": { type: "string" },
|
|
250
257
|
label: { type: "string" },
|
|
258
|
+
relay: { type: "string", short: "r" },
|
|
251
259
|
group: { type: "boolean", default: false },
|
|
252
260
|
"print-only": { type: "boolean", default: false },
|
|
253
261
|
open: { type: "boolean", default: parseBooleanFlag(process.env.PRIVATECLAW_OPEN_QR) },
|
|
@@ -266,6 +274,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
266
274
|
|
|
267
275
|
const ttlMs = parsePositiveIntegerFlag(parsed.values["ttl-ms"], "--ttl-ms");
|
|
268
276
|
const label = parsed.values.label?.trim();
|
|
277
|
+
const relayBaseUrl = parsed.values.relay?.trim();
|
|
269
278
|
const groupMode = parsed.values.group === true;
|
|
270
279
|
const printOnly = parsed.values["print-only"] === true;
|
|
271
280
|
const openInBrowser = parsed.values.open === true;
|
|
@@ -285,7 +294,14 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
285
294
|
? await readHandoffState(resumeSnapshotFile)
|
|
286
295
|
: undefined;
|
|
287
296
|
const resolved = createProvider(
|
|
288
|
-
handoffState
|
|
297
|
+
handoffState
|
|
298
|
+
? {
|
|
299
|
+
providerId: handoffState.providerId,
|
|
300
|
+
...(relayBaseUrl ? { relayBaseUrl } : {}),
|
|
301
|
+
}
|
|
302
|
+
: relayBaseUrl
|
|
303
|
+
? { relayBaseUrl }
|
|
304
|
+
: undefined,
|
|
289
305
|
);
|
|
290
306
|
provider = resolved.provider;
|
|
291
307
|
if (handoffState) {
|
|
@@ -333,7 +349,9 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
333
349
|
}
|
|
334
350
|
|
|
335
351
|
if (printOnly || foreground) {
|
|
336
|
-
const { provider, stateDir } = createProvider(
|
|
352
|
+
const { provider, stateDir } = createProvider(
|
|
353
|
+
relayBaseUrl ? { relayBaseUrl } : undefined,
|
|
354
|
+
);
|
|
337
355
|
const controlServer =
|
|
338
356
|
printOnly
|
|
339
357
|
? undefined
|
|
@@ -364,7 +382,12 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
364
382
|
await handoffForegroundPairToBackground({
|
|
365
383
|
cliModuleUrl: import.meta.url,
|
|
366
384
|
stateDir,
|
|
367
|
-
env:
|
|
385
|
+
env: relayBaseUrl
|
|
386
|
+
? {
|
|
387
|
+
...process.env,
|
|
388
|
+
PRIVATECLAW_RELAY_BASE_URL: relayBaseUrl,
|
|
389
|
+
}
|
|
390
|
+
: process.env,
|
|
368
391
|
handoffState: provider.exportHandoffState(),
|
|
369
392
|
});
|
|
370
393
|
return formatBilingualInline(
|
|
@@ -387,7 +410,12 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
387
410
|
const bundle = await spawnBackgroundPairDaemon({
|
|
388
411
|
cliModuleUrl: import.meta.url,
|
|
389
412
|
stateDir: resolvePrivateClawStateDir(),
|
|
390
|
-
env:
|
|
413
|
+
env: relayBaseUrl
|
|
414
|
+
? {
|
|
415
|
+
...process.env,
|
|
416
|
+
PRIVATECLAW_RELAY_BASE_URL: relayBaseUrl,
|
|
417
|
+
}
|
|
418
|
+
: process.env,
|
|
391
419
|
...(typeof ttlMs === "number" ? { ttlMs } : {}),
|
|
392
420
|
...(label ? { label } : {}),
|
|
393
421
|
...(groupMode ? { groupMode: true } : {}),
|
|
@@ -250,6 +250,119 @@ test("privateclaw command embeds qqimg tags for QQ channel replies", async (t) =
|
|
|
250
250
|
assert.deepEqual(qrPng.subarray(0, PNG_SIGNATURE.length), PNG_SIGNATURE);
|
|
251
251
|
});
|
|
252
252
|
|
|
253
|
+
test("privateclaw command can override the relay per invocation", async (t) => {
|
|
254
|
+
const defaultRelay = createRelayServer({
|
|
255
|
+
host: "127.0.0.1",
|
|
256
|
+
port: 0,
|
|
257
|
+
sessionTtlMs: 60_000,
|
|
258
|
+
frameCacheSize: 8,
|
|
259
|
+
});
|
|
260
|
+
const overrideRelay = createRelayServer({
|
|
261
|
+
host: "127.0.0.1",
|
|
262
|
+
port: 0,
|
|
263
|
+
sessionTtlMs: 60_000,
|
|
264
|
+
frameCacheSize: 8,
|
|
265
|
+
});
|
|
266
|
+
const [{ port: defaultPort }, { port: overridePort }] = await Promise.all([
|
|
267
|
+
defaultRelay.start(),
|
|
268
|
+
overrideRelay.start(),
|
|
269
|
+
]);
|
|
270
|
+
|
|
271
|
+
const stateDir = await mkdtemp(path.join(os.tmpdir(), "privateclaw-plugin-state-"));
|
|
272
|
+
t.after(async () => {
|
|
273
|
+
await rm(stateDir, { recursive: true, force: true });
|
|
274
|
+
await Promise.all([defaultRelay.stop(), overrideRelay.stop()]);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
const plugin = createOpenClawCompatiblePlugin({
|
|
278
|
+
providerWsUrl: `ws://127.0.0.1:${defaultPort}/ws/provider`,
|
|
279
|
+
appWsUrl: `ws://127.0.0.1:${defaultPort}/ws/app`,
|
|
280
|
+
bridge: new EchoBridge("OpenClaw bridge"),
|
|
281
|
+
welcomeMessage: "Welcome to PrivateClaw",
|
|
282
|
+
});
|
|
283
|
+
const { api, getCli, getCommand, getService } = createMockApi();
|
|
284
|
+
plugin.register(api);
|
|
285
|
+
|
|
286
|
+
const service = getService();
|
|
287
|
+
await service.start({
|
|
288
|
+
config: {},
|
|
289
|
+
stateDir,
|
|
290
|
+
logger: api.logger,
|
|
291
|
+
});
|
|
292
|
+
t.after(async () => {
|
|
293
|
+
await service.stop?.({
|
|
294
|
+
config: {},
|
|
295
|
+
stateDir,
|
|
296
|
+
logger: api.logger,
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const command = getCommand();
|
|
301
|
+
const defaultReply = await command.handler({
|
|
302
|
+
channel: "telegram",
|
|
303
|
+
senderId: "tester",
|
|
304
|
+
isAuthorizedSender: true,
|
|
305
|
+
commandBody: "/privateclaw",
|
|
306
|
+
config: {},
|
|
307
|
+
});
|
|
308
|
+
const defaultInviteUri =
|
|
309
|
+
defaultReply.text?.match(/privateclaw:\/\/connect\?payload=\S+/)?.[0];
|
|
310
|
+
assert.ok(defaultInviteUri, "default command should print a PrivateClaw invite URI");
|
|
311
|
+
const defaultInvite = decodeInviteString(defaultInviteUri);
|
|
312
|
+
assert.match(defaultInvite.appWsUrl, new RegExp(`:${defaultPort}/ws/app`));
|
|
313
|
+
|
|
314
|
+
const overrideReply = await command.handler({
|
|
315
|
+
channel: "telegram",
|
|
316
|
+
senderId: "tester",
|
|
317
|
+
isAuthorizedSender: true,
|
|
318
|
+
commandBody: `/privateclaw relay=ws://127.0.0.1:${overridePort}`,
|
|
319
|
+
args: `relay=ws://127.0.0.1:${overridePort}`,
|
|
320
|
+
config: {},
|
|
321
|
+
});
|
|
322
|
+
const overrideInviteUri =
|
|
323
|
+
overrideReply.text?.match(/privateclaw:\/\/connect\?payload=\S+/)?.[0];
|
|
324
|
+
assert.ok(
|
|
325
|
+
overrideInviteUri,
|
|
326
|
+
"override command should print a PrivateClaw invite URI",
|
|
327
|
+
);
|
|
328
|
+
const overrideInvite = decodeInviteString(overrideInviteUri);
|
|
329
|
+
assert.match(overrideInvite.appWsUrl, new RegExp(`:${overridePort}/ws/app`));
|
|
330
|
+
assert.equal(overrideInvite.relayLabel, `127.0.0.1:${overridePort}`);
|
|
331
|
+
|
|
332
|
+
const cli = getCli();
|
|
333
|
+
const root = new FakeCliCommand("root");
|
|
334
|
+
await cli.registrar({
|
|
335
|
+
program: root,
|
|
336
|
+
config: {},
|
|
337
|
+
logger: api.logger,
|
|
338
|
+
});
|
|
339
|
+
const sessions = root.children.get("privateclaw")?.children.get("sessions");
|
|
340
|
+
assert.ok(
|
|
341
|
+
sessions?.actionHandler,
|
|
342
|
+
"plugin should register the privateclaw sessions subcommand",
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
const printed: string[] = [];
|
|
346
|
+
const originalLog = console.log;
|
|
347
|
+
console.log = (message?: unknown, ...optionalParams: unknown[]) => {
|
|
348
|
+
printed.push([message, ...optionalParams].map(String).join(" "));
|
|
349
|
+
};
|
|
350
|
+
t.after(() => {
|
|
351
|
+
console.log = originalLog;
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
await sessions.actionHandler?.();
|
|
355
|
+
|
|
356
|
+
assert.ok(
|
|
357
|
+
printed.some((line) => line.includes(defaultInvite.sessionId)),
|
|
358
|
+
"sessions should include the default-relay session",
|
|
359
|
+
);
|
|
360
|
+
assert.ok(
|
|
361
|
+
printed.some((line) => line.includes(overrideInvite.sessionId)),
|
|
362
|
+
"sessions should include the override-relay session",
|
|
363
|
+
);
|
|
364
|
+
});
|
|
365
|
+
|
|
253
366
|
test("privateclaw plugin local pair CLI defaults to the long session TTL", async (t) => {
|
|
254
367
|
const relay = createRelayServer({
|
|
255
368
|
host: "127.0.0.1",
|
|
@@ -347,6 +460,85 @@ test("privateclaw plugin local pair CLI defaults to the long session TTL", async
|
|
|
347
460
|
assert.deepEqual(qrPng.subarray(0, PNG_SIGNATURE.length), PNG_SIGNATURE);
|
|
348
461
|
});
|
|
349
462
|
|
|
463
|
+
test("privateclaw plugin local pair CLI can override the relay per command", async (t) => {
|
|
464
|
+
const defaultRelay = createRelayServer({
|
|
465
|
+
host: "127.0.0.1",
|
|
466
|
+
port: 0,
|
|
467
|
+
sessionTtlMs: 60_000,
|
|
468
|
+
frameCacheSize: 8,
|
|
469
|
+
});
|
|
470
|
+
const overrideRelay = createRelayServer({
|
|
471
|
+
host: "127.0.0.1",
|
|
472
|
+
port: 0,
|
|
473
|
+
sessionTtlMs: 60_000,
|
|
474
|
+
frameCacheSize: 8,
|
|
475
|
+
});
|
|
476
|
+
const [{ port: defaultPort }, { port: overridePort }] = await Promise.all([
|
|
477
|
+
defaultRelay.start(),
|
|
478
|
+
overrideRelay.start(),
|
|
479
|
+
]);
|
|
480
|
+
|
|
481
|
+
t.after(async () => {
|
|
482
|
+
await Promise.all([defaultRelay.stop(), overrideRelay.stop()]);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
const plugin = createOpenClawCompatiblePlugin({
|
|
486
|
+
providerWsUrl: `ws://127.0.0.1:${defaultPort}/ws/provider`,
|
|
487
|
+
appWsUrl: `ws://127.0.0.1:${defaultPort}/ws/app`,
|
|
488
|
+
bridge: new EchoBridge("OpenClaw bridge"),
|
|
489
|
+
});
|
|
490
|
+
const { api, getCli } = createMockApi();
|
|
491
|
+
plugin.register(api);
|
|
492
|
+
|
|
493
|
+
const cli = getCli();
|
|
494
|
+
const root = new FakeCliCommand("root");
|
|
495
|
+
await cli.registrar({
|
|
496
|
+
program: root,
|
|
497
|
+
config: {},
|
|
498
|
+
logger: api.logger,
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
const pair = root.children.get("privateclaw")?.children.get("pair");
|
|
502
|
+
assert.ok(pair?.actionHandler, "plugin should register the privateclaw pair subcommand");
|
|
503
|
+
|
|
504
|
+
const stateDir = await mkdtemp(path.join(os.tmpdir(), "privateclaw-cli-state-"));
|
|
505
|
+
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
|
|
506
|
+
process.env.OPENCLAW_STATE_DIR = stateDir;
|
|
507
|
+
t.after(async () => {
|
|
508
|
+
if (previousStateDir == null) {
|
|
509
|
+
delete process.env.OPENCLAW_STATE_DIR;
|
|
510
|
+
} else {
|
|
511
|
+
process.env.OPENCLAW_STATE_DIR = previousStateDir;
|
|
512
|
+
}
|
|
513
|
+
await rm(stateDir, { recursive: true, force: true });
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
const printed: string[] = [];
|
|
517
|
+
const originalLog = console.log;
|
|
518
|
+
console.log = (message?: unknown, ...optionalParams: unknown[]) => {
|
|
519
|
+
printed.push([message, ...optionalParams].map(String).join(" "));
|
|
520
|
+
};
|
|
521
|
+
t.after(() => {
|
|
522
|
+
console.log = originalLog;
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
await pair.actionHandler({
|
|
526
|
+
label: "CLI pairing session",
|
|
527
|
+
relay: `ws://127.0.0.1:${overridePort}`,
|
|
528
|
+
printOnly: true,
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
const inviteUri = printed.find((line) =>
|
|
532
|
+
line.startsWith("邀请链接 / Invite URI: privateclaw://connect?payload="),
|
|
533
|
+
);
|
|
534
|
+
assert.ok(inviteUri, "pair command should print a PrivateClaw invite URI");
|
|
535
|
+
const invite = decodeInviteString(
|
|
536
|
+
inviteUri.replace("邀请链接 / Invite URI: ", ""),
|
|
537
|
+
);
|
|
538
|
+
assert.match(invite.appWsUrl, new RegExp(`:${overridePort}/ws/app`));
|
|
539
|
+
assert.equal(invite.relayLabel, `127.0.0.1:${overridePort}`);
|
|
540
|
+
});
|
|
541
|
+
|
|
350
542
|
test("privateclaw CLI can list and remove active group-session participants", async (t) => {
|
|
351
543
|
const relay = createRelayServer({
|
|
352
544
|
host: "127.0.0.1",
|