@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
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
buildManagedSessionQrLegacyLines,
|
|
22
22
|
closeManagedSessionsFromStateDir,
|
|
23
23
|
closeManagedSessionFromStateDir,
|
|
24
|
+
followManagedSessionLogFromStateDir,
|
|
24
25
|
getManagedSessionQrBundleFromStateDir,
|
|
25
26
|
isManagedSessionQrLegacyResult,
|
|
26
27
|
listManagedSessionsFromStateDir,
|
|
@@ -84,6 +85,19 @@ function waitForClose(socket: WebSocket): Promise<void> {
|
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
async function waitForCondition(
|
|
89
|
+
predicate: () => boolean,
|
|
90
|
+
timeoutMs = 2_000,
|
|
91
|
+
): Promise<void> {
|
|
92
|
+
const startedAt = Date.now();
|
|
93
|
+
while (!predicate()) {
|
|
94
|
+
if (Date.now() - startedAt >= timeoutMs) {
|
|
95
|
+
throw new Error("Timed out waiting for test condition.");
|
|
96
|
+
}
|
|
97
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
async function spawnLegacyManagedSessionHost(params: {
|
|
88
102
|
stateDir: string;
|
|
89
103
|
sessionId: string;
|
|
@@ -328,6 +342,72 @@ test("session control can print and notify a managed session QR", async (t) => {
|
|
|
328
342
|
await Promise.all([waitForClose(appOne), waitForClose(appTwo)]);
|
|
329
343
|
});
|
|
330
344
|
|
|
345
|
+
test("session control can follow a managed OpenClaw session log", async (t) => {
|
|
346
|
+
const stateDir = await mkdtemp(path.join(os.tmpdir(), "privateclaw-session-control-follow-"));
|
|
347
|
+
t.after(async () => {
|
|
348
|
+
await rm(stateDir, { recursive: true, force: true });
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const sessionId = "follow-session";
|
|
352
|
+
const child = await spawnLegacyManagedSessionHost({
|
|
353
|
+
stateDir,
|
|
354
|
+
sessionId,
|
|
355
|
+
});
|
|
356
|
+
t.after(async () => {
|
|
357
|
+
if (!child.killed && child.exitCode == null) {
|
|
358
|
+
child.kill("SIGTERM");
|
|
359
|
+
}
|
|
360
|
+
if (child.exitCode == null) {
|
|
361
|
+
await new Promise<void>((resolve) => {
|
|
362
|
+
child.once("exit", () => resolve());
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
const printed: string[] = [];
|
|
368
|
+
const controller = new AbortController();
|
|
369
|
+
const followPromise = followManagedSessionLogFromStateDir({
|
|
370
|
+
stateDir,
|
|
371
|
+
sessionId,
|
|
372
|
+
pollMs: 10,
|
|
373
|
+
signal: controller.signal,
|
|
374
|
+
writeLine: (line) => {
|
|
375
|
+
printed.push(line);
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const logPath = path.join(stateDir, "agents", "main", "sessions", `${sessionId}.jsonl`);
|
|
380
|
+
await mkdir(path.dirname(logPath), { recursive: true });
|
|
381
|
+
const firstLine = JSON.stringify({
|
|
382
|
+
type: "message",
|
|
383
|
+
message: {
|
|
384
|
+
role: "assistant",
|
|
385
|
+
content: [{ type: "text", text: "hello from follow test" }],
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
await writeFile(logPath, `${firstLine}\n`, "utf8");
|
|
389
|
+
await waitForCondition(() => printed.includes(firstLine));
|
|
390
|
+
|
|
391
|
+
const secondLine = JSON.stringify({
|
|
392
|
+
type: "message",
|
|
393
|
+
message: {
|
|
394
|
+
role: "toolResult",
|
|
395
|
+
content: [{ type: "text", text: "tool output" }],
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
await writeFile(logPath, `${firstLine}\n${secondLine}\n`, "utf8");
|
|
399
|
+
await waitForCondition(() => printed.includes(secondLine));
|
|
400
|
+
|
|
401
|
+
controller.abort();
|
|
402
|
+
await followPromise;
|
|
403
|
+
|
|
404
|
+
assert.ok(
|
|
405
|
+
printed.some((line) => line.includes(`Following the OpenClaw session log for session ${sessionId}`)),
|
|
406
|
+
);
|
|
407
|
+
assert.ok(printed.includes(firstLine));
|
|
408
|
+
assert.ok(printed.includes(secondLine));
|
|
409
|
+
});
|
|
410
|
+
|
|
331
411
|
test("session control can terminate a managed session", async (t) => {
|
|
332
412
|
const relay = createRelayServer({
|
|
333
413
|
host: "127.0.0.1",
|
package/src/session-control.ts
CHANGED
|
@@ -254,6 +254,60 @@ export function resolvePrivateClawControlDir(stateDir: string): string {
|
|
|
254
254
|
return path.join(resolvePrivateClawStateDir(stateDir), "privateclaw", "control");
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
async function resolveOpenClawSessionLogPath(params: {
|
|
258
|
+
stateDir: string;
|
|
259
|
+
sessionId: string;
|
|
260
|
+
}): Promise<string | undefined> {
|
|
261
|
+
const agentsDir = path.join(resolvePrivateClawStateDir(params.stateDir), "agents");
|
|
262
|
+
try {
|
|
263
|
+
const agentEntries = await readdir(agentsDir, { withFileTypes: true });
|
|
264
|
+
for (const entry of agentEntries) {
|
|
265
|
+
if (!entry.isDirectory()) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const candidate = path.join(agentsDir, entry.name, "sessions", `${params.sessionId}.jsonl`);
|
|
269
|
+
try {
|
|
270
|
+
await access(candidate);
|
|
271
|
+
return candidate;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
274
|
+
if (code === "ENOENT") {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
} catch (error) {
|
|
281
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
282
|
+
if (code === "ENOENT") {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function waitForPollInterval(
|
|
292
|
+
pollMs: number,
|
|
293
|
+
signal?: AbortSignal,
|
|
294
|
+
): Promise<void> {
|
|
295
|
+
if (signal?.aborted) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
await new Promise<void>((resolve) => {
|
|
299
|
+
const timeout = setTimeout(() => {
|
|
300
|
+
signal?.removeEventListener("abort", handleAbort);
|
|
301
|
+
resolve();
|
|
302
|
+
}, pollMs);
|
|
303
|
+
const handleAbort = () => {
|
|
304
|
+
clearTimeout(timeout);
|
|
305
|
+
resolve();
|
|
306
|
+
};
|
|
307
|
+
signal?.addEventListener("abort", handleAbort, { once: true });
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
257
311
|
export function buildManagedSessionsReportLines(
|
|
258
312
|
listings: ReadonlyArray<PrivateClawDiscoveredSessionListing>,
|
|
259
313
|
): string[] {
|
|
@@ -827,3 +881,100 @@ export async function getManagedSessionQrBundleFromStateDir(params: {
|
|
|
827
881
|
throw error;
|
|
828
882
|
}
|
|
829
883
|
}
|
|
884
|
+
|
|
885
|
+
export async function followManagedSessionLogFromStateDir(params: {
|
|
886
|
+
stateDir: string;
|
|
887
|
+
sessionId: string;
|
|
888
|
+
writeLine?: (line: string) => void;
|
|
889
|
+
pollMs?: number;
|
|
890
|
+
signal?: AbortSignal;
|
|
891
|
+
}): Promise<void> {
|
|
892
|
+
const writeLine = params.writeLine ?? ((line: string) => console.log(line));
|
|
893
|
+
const pollMs = params.pollMs ?? 250;
|
|
894
|
+
let sessionLogPath = await resolveOpenClawSessionLogPath({
|
|
895
|
+
stateDir: params.stateDir,
|
|
896
|
+
sessionId: params.sessionId,
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
try {
|
|
900
|
+
await resolveManagedSessionDescriptor({
|
|
901
|
+
stateDir: params.stateDir,
|
|
902
|
+
sessionId: params.sessionId,
|
|
903
|
+
});
|
|
904
|
+
} catch (error) {
|
|
905
|
+
if (!sessionLogPath) {
|
|
906
|
+
throw error;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
let announcedWaiting = false;
|
|
911
|
+
let announcedFollow = false;
|
|
912
|
+
let sizeBytes = 0;
|
|
913
|
+
let trailingPartialLine = "";
|
|
914
|
+
|
|
915
|
+
for (;;) {
|
|
916
|
+
if (params.signal?.aborted) {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
if (!sessionLogPath) {
|
|
921
|
+
sessionLogPath = await resolveOpenClawSessionLogPath({
|
|
922
|
+
stateDir: params.stateDir,
|
|
923
|
+
sessionId: params.sessionId,
|
|
924
|
+
});
|
|
925
|
+
if (!sessionLogPath) {
|
|
926
|
+
if (!announcedWaiting) {
|
|
927
|
+
writeLine(
|
|
928
|
+
formatBilingualInline(
|
|
929
|
+
`正在等待会话 ${params.sessionId} 的 OpenClaw session 日志文件出现……`,
|
|
930
|
+
`Waiting for the OpenClaw session log for session ${params.sessionId} to appear...`,
|
|
931
|
+
),
|
|
932
|
+
);
|
|
933
|
+
announcedWaiting = true;
|
|
934
|
+
}
|
|
935
|
+
await waitForPollInterval(pollMs, params.signal);
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
if (!announcedFollow) {
|
|
941
|
+
writeLine(
|
|
942
|
+
formatBilingualInline(
|
|
943
|
+
`开始跟随会话 ${params.sessionId} 的 OpenClaw session 日志:${sessionLogPath}`,
|
|
944
|
+
`Following the OpenClaw session log for session ${params.sessionId}: ${sessionLogPath}`,
|
|
945
|
+
),
|
|
946
|
+
);
|
|
947
|
+
announcedFollow = true;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
try {
|
|
951
|
+
const sessionLogBuffer = await readFile(sessionLogPath);
|
|
952
|
+
if (sessionLogBuffer.length < sizeBytes) {
|
|
953
|
+
sizeBytes = 0;
|
|
954
|
+
trailingPartialLine = "";
|
|
955
|
+
}
|
|
956
|
+
const deltaBuffer = sessionLogBuffer.subarray(sizeBytes);
|
|
957
|
+
if (deltaBuffer.length > 0) {
|
|
958
|
+
const chunk = trailingPartialLine + deltaBuffer.toString("utf8");
|
|
959
|
+
const lines = chunk.split(/\r?\n/gu);
|
|
960
|
+
trailingPartialLine = lines.pop() ?? "";
|
|
961
|
+
for (const line of lines) {
|
|
962
|
+
if (line.trim() !== "") {
|
|
963
|
+
writeLine(line);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
sizeBytes = sessionLogBuffer.length;
|
|
967
|
+
}
|
|
968
|
+
} catch (error) {
|
|
969
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
970
|
+
if (code === "ENOENT") {
|
|
971
|
+
sessionLogPath = undefined;
|
|
972
|
+
announcedFollow = false;
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
throw error;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
await waitForPollInterval(pollMs, params.signal);
|
|
979
|
+
}
|
|
980
|
+
}
|
package/src/text.ts
CHANGED
|
@@ -57,6 +57,11 @@ export const PRIVATECLAW_CLI_SESSIONS_QR_DESCRIPTION = formatBilingualInline(
|
|
|
57
57
|
"Print the QR code for a selected session, optionally open a browser preview, and optionally notify the current participants.",
|
|
58
58
|
);
|
|
59
59
|
|
|
60
|
+
export const PRIVATECLAW_CLI_SESSIONS_FOLLOW_DESCRIPTION = formatBilingualInline(
|
|
61
|
+
"跟随指定会话的 OpenClaw session JSONL 日志,便于实时排障。",
|
|
62
|
+
"Follow the OpenClaw session JSONL log for a selected session to debug it in real time.",
|
|
63
|
+
);
|
|
64
|
+
|
|
60
65
|
export const PRIVATECLAW_CLI_SESSIONS_KILL_DESCRIPTION = formatBilingualInline(
|
|
61
66
|
"终止指定的活动会话;对于旧的后台 daemon,会回退为终止整个 daemon host。",
|
|
62
67
|
"Terminate a selected active session; for older background daemons, this falls back to terminating the whole daemon host.",
|
|
@@ -113,6 +118,11 @@ export const PRIVATECLAW_CLI_FOREGROUND_OPTION_DESCRIPTION = formatBilingualInli
|
|
|
113
118
|
"Keep the current command in the foreground until the session ends or you press Ctrl+C; in supported runtimes you can also press Ctrl+D to move it into the background.",
|
|
114
119
|
);
|
|
115
120
|
|
|
121
|
+
export const PRIVATECLAW_CLI_VERBOSE_OPTION_DESCRIPTION = formatBilingualInline(
|
|
122
|
+
"输出更详细的 provider / bridge 调试日志。",
|
|
123
|
+
"Emit more detailed provider / bridge debug logs.",
|
|
124
|
+
);
|
|
125
|
+
|
|
116
126
|
export const PRIVATECLAW_INVITE_URI_LABEL = formatBilingualInline(
|
|
117
127
|
"邀请链接",
|
|
118
128
|
"Invite URI",
|
|
@@ -172,8 +182,8 @@ export function buildPrivateClawCommandErrorMessage(details: string): string {
|
|
|
172
182
|
}
|
|
173
183
|
|
|
174
184
|
export const PRIVATECLAW_RENEW_SESSION_DESCRIPTION = formatBilingualInline(
|
|
175
|
-
"轮换当前 PrivateClaw 会话密钥,并将当前会话延长
|
|
176
|
-
"Rotate the current PrivateClaw session key and extend this session by
|
|
185
|
+
"轮换当前 PrivateClaw 会话密钥,并将当前会话延长 24 小时。",
|
|
186
|
+
"Rotate the current PrivateClaw session key and extend this session by 24 hours.",
|
|
177
187
|
);
|
|
178
188
|
|
|
179
189
|
export const PRIVATECLAW_SESSION_QR_DESCRIPTION = formatBilingualInline(
|
package/src/types.ts
CHANGED
|
@@ -3,11 +3,13 @@ import type {
|
|
|
3
3
|
PrivateClawInvite,
|
|
4
4
|
PrivateClawParticipant,
|
|
5
5
|
PrivateClawSlashCommand,
|
|
6
|
+
PrivateClawThinkingEntry,
|
|
7
|
+
PrivateClawThinkingStatus,
|
|
6
8
|
} from "@privateclaw/protocol";
|
|
7
9
|
|
|
8
10
|
export interface PrivateClawConversationTurn {
|
|
9
11
|
messageId: string;
|
|
10
|
-
role: "user" | "assistant" | "system";
|
|
12
|
+
role: "user" | "assistant" | "system" | "thinking";
|
|
11
13
|
text: string;
|
|
12
14
|
sentAt: string;
|
|
13
15
|
bridgeText?: string;
|
|
@@ -16,6 +18,9 @@ export interface PrivateClawConversationTurn {
|
|
|
16
18
|
replyTo?: string;
|
|
17
19
|
severity?: "info" | "error";
|
|
18
20
|
attachments?: PrivateClawAttachment[];
|
|
21
|
+
thinkingStatus?: PrivateClawThinkingStatus;
|
|
22
|
+
thinkingSummary?: string;
|
|
23
|
+
thinkingEntries?: PrivateClawThinkingEntry[];
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
export type BridgeMessage =
|
|
@@ -38,13 +43,33 @@ export interface PrivateClawAudioTranscriptionRequest {
|
|
|
38
43
|
attachments: ReadonlyArray<PrivateClawAttachment>;
|
|
39
44
|
}
|
|
40
45
|
|
|
46
|
+
export interface PrivateClawAudioTranscriber {
|
|
47
|
+
transcribeAudioAttachments(
|
|
48
|
+
params: PrivateClawAudioTranscriptionRequest,
|
|
49
|
+
): Promise<string>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface PrivateClawVerboseController {
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface PrivateClawThinkingTraceSnapshot {
|
|
57
|
+
entries: ReadonlyArray<PrivateClawThinkingEntry>;
|
|
58
|
+
sentAt: string;
|
|
59
|
+
summary: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
41
62
|
export interface PrivateClawAgentBridge {
|
|
63
|
+
supportsThinkingTrace?: boolean;
|
|
42
64
|
handleUserMessage(params: {
|
|
43
65
|
sessionId: string;
|
|
44
66
|
invite: PrivateClawInvite;
|
|
45
67
|
message: string;
|
|
46
68
|
attachments?: ReadonlyArray<PrivateClawAttachment>;
|
|
47
69
|
history: ReadonlyArray<PrivateClawConversationTurn>;
|
|
70
|
+
onThinkingTrace?: (
|
|
71
|
+
snapshot: PrivateClawThinkingTraceSnapshot,
|
|
72
|
+
) => void | Promise<void>;
|
|
48
73
|
}): Promise<BridgeResponse>;
|
|
49
74
|
transcribeAudioAttachments?(
|
|
50
75
|
params: PrivateClawAudioTranscriptionRequest,
|
|
@@ -55,16 +80,19 @@ export interface PrivateClawProviderOptions {
|
|
|
55
80
|
providerWsUrl: string;
|
|
56
81
|
appWsUrl: string;
|
|
57
82
|
bridge: PrivateClawAgentBridge;
|
|
83
|
+
audioTranscriber?: PrivateClawAudioTranscriber;
|
|
58
84
|
providerId?: string;
|
|
59
85
|
defaultTtlMs?: number;
|
|
60
86
|
providerLabel?: string;
|
|
61
87
|
welcomeMessage?: string;
|
|
62
88
|
commandsProvider?: () => Promise<PrivateClawSlashCommand[]>;
|
|
89
|
+
verboseController?: PrivateClawVerboseController;
|
|
63
90
|
onLog?: (message: string) => void;
|
|
64
91
|
}
|
|
65
92
|
|
|
66
93
|
export interface ProviderParticipantState extends PrivateClawParticipant {
|
|
67
94
|
lastSeenAt: string;
|
|
95
|
+
supportsThinkingTrace?: boolean;
|
|
68
96
|
}
|
|
69
97
|
|
|
70
98
|
export interface PrivateClawManagedSession {
|