@privateclaw/privateclaw 0.1.16 → 0.1.18
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 +44 -1
- package/dist/audio-transcriber.d.ts +46 -0
- package/dist/audio-transcriber.js +433 -0
- package/dist/audio-transcriber.js.map +1 -0
- package/dist/bridges/openai-compatible-bridge.js +1 -0
- package/dist/bridges/openai-compatible-bridge.js.map +1 -1
- package/dist/bridges/openclaw-agent-bridge.d.ts +10 -2
- package/dist/bridges/openclaw-agent-bridge.js +632 -73
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/cli.js +57 -6
- package/dist/cli.js.map +1 -1
- package/dist/openclaw-plugin.js +150 -51
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/pair-daemon.d.ts +2 -0
- package/dist/pair-daemon.js +2 -0
- package/dist/pair-daemon.js.map +1 -1
- package/dist/provider.d.ts +14 -1
- package/dist/provider.js +262 -20
- package/dist/provider.js.map +1 -1
- package/dist/session-control.d.ts +7 -0
- package/dist/session-control.js +122 -0
- package/dist/session-control.js.map +1 -1
- package/dist/text.d.ts +2 -0
- package/dist/text.js +3 -1
- package/dist/text.js.map +1 -1
- package/dist/types.d.ts +21 -2
- package/package.json +2 -2
- package/src/audio-transcriber.test.ts +299 -0
- package/src/audio-transcriber.ts +615 -0
- package/src/bridges/openai-compatible-bridge.ts +1 -0
- package/src/bridges/openclaw-agent-bridge.test.ts +644 -7
- package/src/bridges/openclaw-agent-bridge.ts +817 -81
- package/src/cli.ts +73 -5
- package/src/openclaw-plugin.test.ts +12 -2
- package/src/openclaw-plugin.ts +191 -54
- package/src/pair-daemon.ts +4 -0
- package/src/provider.test.ts +679 -0
- package/src/provider.ts +349 -28
- package/src/session-control.test.ts +80 -0
- package/src/session-control.ts +151 -0
- package/src/text.ts +12 -2
- package/src/types.ts +29 -1
package/src/cli.ts
CHANGED
|
@@ -5,6 +5,9 @@ import { parseArgs } from "node:util";
|
|
|
5
5
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { EchoBridge } from "./bridges/echo-bridge.js";
|
|
8
|
+
import {
|
|
9
|
+
buildPreferredAudioTranscriber,
|
|
10
|
+
} from "./audio-transcriber.js";
|
|
8
11
|
import { OpenClawAgentBridge } from "./bridges/openclaw-agent-bridge.js";
|
|
9
12
|
import { OpenAICompatibleBridge } from "./bridges/openai-compatible-bridge.js";
|
|
10
13
|
import { WebhookBridge } from "./bridges/webhook-bridge.js";
|
|
@@ -26,6 +29,7 @@ import { DEFAULT_RELAY_BASE_URL } from "./relay-defaults.js";
|
|
|
26
29
|
import { resolveRelayEndpoints } from "./relay-endpoints.js";
|
|
27
30
|
import {
|
|
28
31
|
buildManagedSessionQrLegacyLines,
|
|
32
|
+
followManagedSessionLogFromStateDir,
|
|
29
33
|
buildManagedSessionsReportLines,
|
|
30
34
|
closeManagedSessionsFromStateDir,
|
|
31
35
|
closeManagedSessionFromStateDir,
|
|
@@ -41,11 +45,16 @@ import {
|
|
|
41
45
|
formatBilingualInline,
|
|
42
46
|
PRIVATECLAW_CLI_NOTIFY_OPTION_DESCRIPTION,
|
|
43
47
|
PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION,
|
|
48
|
+
PRIVATECLAW_CLI_SESSIONS_FOLLOW_DESCRIPTION,
|
|
44
49
|
PRIVATECLAW_CLI_SESSIONS_KILL_DESCRIPTION,
|
|
45
50
|
PRIVATECLAW_CLI_SESSIONS_KILLALL_DESCRIPTION,
|
|
46
51
|
PRIVATECLAW_CLI_SESSIONS_QR_DESCRIPTION,
|
|
52
|
+
PRIVATECLAW_CLI_VERBOSE_OPTION_DESCRIPTION,
|
|
47
53
|
} from "./text.js";
|
|
48
|
-
import type {
|
|
54
|
+
import type {
|
|
55
|
+
PrivateClawProviderHandoffState,
|
|
56
|
+
PrivateClawVerboseController,
|
|
57
|
+
} from "./types.js";
|
|
49
58
|
|
|
50
59
|
type BridgeMode =
|
|
51
60
|
| "echo"
|
|
@@ -112,6 +121,7 @@ function detectBridgeMode(): BridgeMode {
|
|
|
112
121
|
function createProvider(params?: {
|
|
113
122
|
providerId?: string;
|
|
114
123
|
relayBaseUrl?: string;
|
|
124
|
+
verboseController?: PrivateClawVerboseController;
|
|
115
125
|
}): {
|
|
116
126
|
provider: PrivateClawProvider;
|
|
117
127
|
stateDir: string;
|
|
@@ -161,6 +171,8 @@ function createProvider(params?: {
|
|
|
161
171
|
600,
|
|
162
172
|
)
|
|
163
173
|
: undefined;
|
|
174
|
+
const verboseController = params?.verboseController;
|
|
175
|
+
const audioTranscriber = buildCliAudioTranscriber();
|
|
164
176
|
|
|
165
177
|
const bridge =
|
|
166
178
|
bridgeMode === "openclaw-agent"
|
|
@@ -175,6 +187,7 @@ function createProvider(params?: {
|
|
|
175
187
|
? { timeoutSeconds: openClawAgentTimeoutSeconds }
|
|
176
188
|
: {}),
|
|
177
189
|
...(openClawAgentLocal ? { local: true } : {}),
|
|
190
|
+
...(verboseController ? { verboseController } : {}),
|
|
178
191
|
onLog: (message) => {
|
|
179
192
|
console.log(`[privateclaw-provider] ${message}`);
|
|
180
193
|
},
|
|
@@ -212,9 +225,11 @@ function createProvider(params?: {
|
|
|
212
225
|
providerWsUrl: relayEndpoints.providerWsUrl,
|
|
213
226
|
appWsUrl: relayEndpoints.appWsUrl,
|
|
214
227
|
bridge,
|
|
228
|
+
...(audioTranscriber ? { audioTranscriber } : {}),
|
|
215
229
|
...(params?.providerId ? { providerId: params.providerId } : {}),
|
|
216
230
|
defaultTtlMs: ttlMs,
|
|
217
231
|
providerLabel,
|
|
232
|
+
...(verboseController ? { verboseController } : {}),
|
|
218
233
|
commandsProvider: async () => {
|
|
219
234
|
try {
|
|
220
235
|
return await loadAvailableOpenClawCommands();
|
|
@@ -231,6 +246,15 @@ function createProvider(params?: {
|
|
|
231
246
|
};
|
|
232
247
|
}
|
|
233
248
|
|
|
249
|
+
function buildCliAudioTranscriber() {
|
|
250
|
+
return buildPreferredAudioTranscriber({
|
|
251
|
+
env: process.env,
|
|
252
|
+
onLog: (message) => {
|
|
253
|
+
console.log(`[privateclaw-provider] ${message}`);
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
234
258
|
async function waitForSessionsToDrain(
|
|
235
259
|
provider: PrivateClawProvider,
|
|
236
260
|
): Promise<void> {
|
|
@@ -256,15 +280,18 @@ async function readHandoffState(
|
|
|
256
280
|
function printHelp(): void {
|
|
257
281
|
console.log(`privateclaw-provider <pair|sessions|kick|killall>
|
|
258
282
|
|
|
259
|
-
pair [--ttl-ms <ms>] [--label <label>] [--relay <url>] [--group] [--print-only] [--open] [--foreground]
|
|
283
|
+
pair [--ttl-ms <ms>] [--label <label>] [--relay <url>] [--group] [--print-only] [--open] [--foreground] [--verbose]
|
|
260
284
|
sessions
|
|
285
|
+
sessions follow <sessionId>
|
|
261
286
|
sessions qr <sessionId> [--open] [--notify]
|
|
262
287
|
sessions kill <sessionId>
|
|
263
288
|
sessions killall
|
|
264
289
|
killall
|
|
265
290
|
kick <sessionId> <appId>`);
|
|
266
291
|
console.log(`\n--relay <url>: ${PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION}`);
|
|
292
|
+
console.log(`--verbose: ${PRIVATECLAW_CLI_VERBOSE_OPTION_DESCRIPTION}`);
|
|
267
293
|
console.log(`--notify: ${PRIVATECLAW_CLI_NOTIFY_OPTION_DESCRIPTION}`);
|
|
294
|
+
console.log(`sessions follow: ${PRIVATECLAW_CLI_SESSIONS_FOLLOW_DESCRIPTION}`);
|
|
268
295
|
console.log(`sessions qr: ${PRIVATECLAW_CLI_SESSIONS_QR_DESCRIPTION}`);
|
|
269
296
|
console.log(`sessions kill: ${PRIVATECLAW_CLI_SESSIONS_KILL_DESCRIPTION}`);
|
|
270
297
|
console.log(`sessions killall: ${PRIVATECLAW_CLI_SESSIONS_KILLALL_DESCRIPTION}`);
|
|
@@ -283,6 +310,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
283
310
|
"print-only": { type: "boolean", default: false },
|
|
284
311
|
open: { type: "boolean", default: parseBooleanFlag(process.env.PRIVATECLAW_OPEN_QR) },
|
|
285
312
|
foreground: { type: "boolean", default: false },
|
|
313
|
+
verbose: { type: "boolean", default: parseBooleanFlag(process.env.PRIVATECLAW_VERBOSE) },
|
|
286
314
|
"daemon-child": { type: "boolean", default: false },
|
|
287
315
|
"result-file": { type: "string" },
|
|
288
316
|
"resume-snapshot-file": { type: "string" },
|
|
@@ -302,9 +330,11 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
302
330
|
const printOnly = parsed.values["print-only"] === true;
|
|
303
331
|
const openInBrowser = parsed.values.open === true;
|
|
304
332
|
const foreground = parsed.values.foreground === true;
|
|
333
|
+
const verbose = parsed.values.verbose === true;
|
|
305
334
|
const daemonChild = parsed.values["daemon-child"] === true;
|
|
306
335
|
const resultFile = parsed.values["result-file"];
|
|
307
336
|
const resumeSnapshotFile = parsed.values["resume-snapshot-file"];
|
|
337
|
+
const verboseController = { enabled: verbose } satisfies PrivateClawVerboseController;
|
|
308
338
|
|
|
309
339
|
if (daemonChild) {
|
|
310
340
|
if (!resultFile) {
|
|
@@ -321,10 +351,11 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
321
351
|
? {
|
|
322
352
|
providerId: handoffState.providerId,
|
|
323
353
|
...(relayBaseUrl ? { relayBaseUrl } : {}),
|
|
354
|
+
verboseController,
|
|
324
355
|
}
|
|
325
356
|
: relayBaseUrl
|
|
326
|
-
? { relayBaseUrl }
|
|
327
|
-
:
|
|
357
|
+
? { relayBaseUrl, verboseController }
|
|
358
|
+
: { verboseController },
|
|
328
359
|
);
|
|
329
360
|
provider = resolved.provider;
|
|
330
361
|
if (handoffState) {
|
|
@@ -373,7 +404,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
373
404
|
|
|
374
405
|
if (printOnly || foreground) {
|
|
375
406
|
const { provider, stateDir } = createProvider(
|
|
376
|
-
relayBaseUrl ? { relayBaseUrl } :
|
|
407
|
+
relayBaseUrl ? { relayBaseUrl, verboseController } : { verboseController },
|
|
377
408
|
);
|
|
378
409
|
const controlServer =
|
|
379
410
|
printOnly
|
|
@@ -405,6 +436,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
405
436
|
await handoffForegroundPairToBackground({
|
|
406
437
|
cliModuleUrl: import.meta.url,
|
|
407
438
|
stateDir,
|
|
439
|
+
...(verbose ? { verbose: true } : {}),
|
|
408
440
|
env: relayBaseUrl
|
|
409
441
|
? {
|
|
410
442
|
...process.env,
|
|
@@ -443,6 +475,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
443
475
|
...(label ? { label } : {}),
|
|
444
476
|
...(groupMode ? { groupMode: true } : {}),
|
|
445
477
|
...(openInBrowser ? { openInBrowser: true } : {}),
|
|
478
|
+
...(verbose ? { verbose: true } : {}),
|
|
446
479
|
});
|
|
447
480
|
printPairInviteBundle(bundle, (line) => {
|
|
448
481
|
console.log(line);
|
|
@@ -456,6 +489,10 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
456
489
|
}
|
|
457
490
|
|
|
458
491
|
async function runSessionsCommand(args: string[]): Promise<void> {
|
|
492
|
+
if (args[0] === "follow") {
|
|
493
|
+
await runSessionsFollowCommand(args.slice(1));
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
459
496
|
if (args[0] === "qr") {
|
|
460
497
|
await runSessionsQrCommand(args.slice(1));
|
|
461
498
|
return;
|
|
@@ -486,6 +523,37 @@ async function runSessionsCommand(args: string[]): Promise<void> {
|
|
|
486
523
|
}
|
|
487
524
|
}
|
|
488
525
|
|
|
526
|
+
async function runSessionsFollowCommand(args: string[]): Promise<void> {
|
|
527
|
+
const parsed = parseArgs({
|
|
528
|
+
args,
|
|
529
|
+
allowPositionals: true,
|
|
530
|
+
options: {
|
|
531
|
+
help: { type: "boolean", short: "h" },
|
|
532
|
+
},
|
|
533
|
+
});
|
|
534
|
+
if (parsed.values.help) {
|
|
535
|
+
printHelp();
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const sessionId = parsed.positionals[0];
|
|
539
|
+
if (!sessionId) {
|
|
540
|
+
throw new Error(
|
|
541
|
+
formatBilingualInline(
|
|
542
|
+
"`sessions follow` 需要提供 sessionId。",
|
|
543
|
+
"`sessions follow` requires a sessionId.",
|
|
544
|
+
),
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
await followManagedSessionLogFromStateDir({
|
|
549
|
+
stateDir: resolvePrivateClawStateDir(),
|
|
550
|
+
sessionId,
|
|
551
|
+
writeLine: (line: string) => {
|
|
552
|
+
console.log(line);
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
489
557
|
async function runSessionsKillCommand(args: string[]): Promise<void> {
|
|
490
558
|
const parsed = parseArgs({
|
|
491
559
|
args,
|
|
@@ -75,6 +75,7 @@ function createMockApi(): {
|
|
|
75
75
|
|
|
76
76
|
class FakeCliCommand {
|
|
77
77
|
readonly children = new Map<string, FakeCliCommand>();
|
|
78
|
+
readonly options: string[] = [];
|
|
78
79
|
actionHandler: ((...args: unknown[]) => void | Promise<void>) | undefined;
|
|
79
80
|
|
|
80
81
|
constructor(readonly name: string) {}
|
|
@@ -94,6 +95,7 @@ class FakeCliCommand {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
option(_flags: string, _description?: string, _defaultValue?: string | boolean): FakeCliCommand {
|
|
98
|
+
this.options.push(_flags);
|
|
97
99
|
return this;
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -171,7 +173,7 @@ test("privateclaw command writes QR media into the OpenClaw state media director
|
|
|
171
173
|
const remainingMs = new Date(invite.expiresAt).getTime() - Date.now();
|
|
172
174
|
assert.ok(
|
|
173
175
|
remainingMs > DEFAULT_SESSION_TTL_MS - 60_000,
|
|
174
|
-
"new sessions should default to roughly
|
|
176
|
+
"new sessions should default to roughly 24 hours even when relay default TTL is shorter",
|
|
175
177
|
);
|
|
176
178
|
const expectedMediaDir = path.join(stateDir, "media", "privateclaw");
|
|
177
179
|
const mediaPath =
|
|
@@ -341,6 +343,10 @@ test("privateclaw command can override the relay per invocation", async (t) => {
|
|
|
341
343
|
sessions?.actionHandler,
|
|
342
344
|
"plugin should register the privateclaw sessions subcommand",
|
|
343
345
|
);
|
|
346
|
+
assert.ok(
|
|
347
|
+
sessions?.children.get("follow")?.actionHandler,
|
|
348
|
+
"plugin should register the privateclaw sessions follow subcommand",
|
|
349
|
+
);
|
|
344
350
|
assert.ok(
|
|
345
351
|
sessions?.children.get("qr")?.actionHandler,
|
|
346
352
|
"plugin should register the privateclaw sessions qr subcommand",
|
|
@@ -407,6 +413,10 @@ test("privateclaw plugin local pair CLI defaults to the long session TTL", async
|
|
|
407
413
|
|
|
408
414
|
const pair = privateclaw.children.get("pair");
|
|
409
415
|
assert.ok(pair?.actionHandler, "plugin should register the privateclaw pair subcommand");
|
|
416
|
+
assert.ok(
|
|
417
|
+
pair.options.includes("--verbose"),
|
|
418
|
+
"plugin should expose a --verbose flag on the privateclaw pair subcommand",
|
|
419
|
+
);
|
|
410
420
|
|
|
411
421
|
const stateDir = await mkdtemp(path.join(os.tmpdir(), "privateclaw-cli-state-"));
|
|
412
422
|
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
|
|
@@ -461,7 +471,7 @@ test("privateclaw plugin local pair CLI defaults to the long session TTL", async
|
|
|
461
471
|
const remainingMs = new Date(invite.expiresAt).getTime() - Date.now();
|
|
462
472
|
assert.ok(
|
|
463
473
|
remainingMs > DEFAULT_SESSION_TTL_MS - 60_000,
|
|
464
|
-
"local pair sessions should default to roughly
|
|
474
|
+
"local pair sessions should default to roughly 24 hours even when relay default TTL is shorter",
|
|
465
475
|
);
|
|
466
476
|
const qrPath = qrPathLine.replace("二维码 PNG 路径 / QR PNG path: ", "");
|
|
467
477
|
const qrPng = await readFile(qrPath);
|