@privateclaw/privateclaw 0.1.10 → 0.1.12
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 +42 -13
- package/dist/cli.js +347 -62
- package/dist/cli.js.map +1 -1
- package/dist/compat/openclaw.d.ts +1 -0
- package/dist/openclaw-plugin.js +171 -8
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/pair-daemon.d.ts +16 -0
- package/dist/pair-daemon.js +126 -0
- package/dist/pair-daemon.js.map +1 -0
- package/dist/pair-session.d.ts +4 -1
- package/dist/pair-session.js +80 -15
- package/dist/pair-session.js.map +1 -1
- package/dist/provider.d.ts +11 -3
- package/dist/provider.js +160 -8
- package/dist/provider.js.map +1 -1
- package/dist/relay-provider-client.d.ts +6 -0
- package/dist/relay-provider-client.js +30 -3
- package/dist/relay-provider-client.js.map +1 -1
- package/dist/session-control.d.ts +61 -0
- package/dist/session-control.js +292 -0
- package/dist/session-control.js.map +1 -0
- package/dist/text.d.ts +6 -0
- package/dist/text.js +8 -0
- package/dist/text.js.map +1 -1
- package/dist/types.d.ts +32 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +2 -2
- package/src/cli.ts +443 -73
- package/src/compat/openclaw.ts +1 -0
- package/src/openclaw-plugin.test.ts +216 -1
- package/src/openclaw-plugin.ts +237 -7
- package/src/pair-daemon.ts +181 -0
- package/src/pair-session.ts +105 -12
- package/src/provider.test.ts +280 -0
- package/src/provider.ts +209 -9
- package/src/relay-provider-client.ts +41 -4
- package/src/session-control.ts +473 -0
- package/src/text.ts +34 -0
- package/src/types.ts +35 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
|
|
3
|
+
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { type AddressInfo } from "node:net";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { formatBilingualInline } from "./text.js";
|
|
8
|
+
import type { PrivateClawManagedSession } from "./types.js";
|
|
9
|
+
|
|
10
|
+
export type PrivateClawControlHostKind =
|
|
11
|
+
| "plugin-service"
|
|
12
|
+
| "pair-foreground"
|
|
13
|
+
| "pair-daemon";
|
|
14
|
+
|
|
15
|
+
export interface PrivateClawSessionControlDescriptor {
|
|
16
|
+
version: 1;
|
|
17
|
+
controlId: string;
|
|
18
|
+
kind: PrivateClawControlHostKind;
|
|
19
|
+
pid: number;
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
token: string;
|
|
23
|
+
startedAt: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface PrivateClawDiscoveredSessionHost {
|
|
27
|
+
controlId: string;
|
|
28
|
+
kind: PrivateClawControlHostKind;
|
|
29
|
+
pid: number;
|
|
30
|
+
startedAt: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface PrivateClawDiscoveredSessionListing {
|
|
34
|
+
host: PrivateClawDiscoveredSessionHost;
|
|
35
|
+
sessions: PrivateClawManagedSession[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface PrivateClawKickResult {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
participant: {
|
|
41
|
+
appId: string;
|
|
42
|
+
displayName: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PrivateClawSessionControlProvider {
|
|
47
|
+
listManagedSessions(): PrivateClawManagedSession[];
|
|
48
|
+
kickGroupParticipant(
|
|
49
|
+
sessionId: string,
|
|
50
|
+
appId: string,
|
|
51
|
+
reason?: string,
|
|
52
|
+
): Promise<{
|
|
53
|
+
appId: string;
|
|
54
|
+
displayName: string;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function writeJson(
|
|
59
|
+
response: ServerResponse,
|
|
60
|
+
statusCode: number,
|
|
61
|
+
payload: unknown,
|
|
62
|
+
): void {
|
|
63
|
+
response.statusCode = statusCode;
|
|
64
|
+
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
65
|
+
response.end(JSON.stringify(payload));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function readBearerToken(request: IncomingMessage): string | undefined {
|
|
69
|
+
const header = request.headers.authorization;
|
|
70
|
+
if (!header?.startsWith("Bearer ")) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return header.slice("Bearer ".length).trim();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function readJsonBody(request: IncomingMessage): Promise<unknown> {
|
|
77
|
+
const chunks: Buffer[] = [];
|
|
78
|
+
for await (const chunk of request) {
|
|
79
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
80
|
+
}
|
|
81
|
+
if (chunks.length === 0) {
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8")) as unknown;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function toHostSummary(
|
|
88
|
+
descriptor: PrivateClawSessionControlDescriptor,
|
|
89
|
+
): PrivateClawDiscoveredSessionHost {
|
|
90
|
+
return {
|
|
91
|
+
controlId: descriptor.controlId,
|
|
92
|
+
kind: descriptor.kind,
|
|
93
|
+
pid: descriptor.pid,
|
|
94
|
+
startedAt: descriptor.startedAt,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isDescriptor(
|
|
99
|
+
value: unknown,
|
|
100
|
+
): value is PrivateClawSessionControlDescriptor {
|
|
101
|
+
if (!value || typeof value !== "object") {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const descriptor = value as Record<string, unknown>;
|
|
105
|
+
return (
|
|
106
|
+
descriptor.version === 1 &&
|
|
107
|
+
typeof descriptor.controlId === "string" &&
|
|
108
|
+
typeof descriptor.kind === "string" &&
|
|
109
|
+
typeof descriptor.pid === "number" &&
|
|
110
|
+
typeof descriptor.host === "string" &&
|
|
111
|
+
typeof descriptor.port === "number" &&
|
|
112
|
+
typeof descriptor.token === "string" &&
|
|
113
|
+
typeof descriptor.startedAt === "string"
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function listDescriptorPaths(controlDir: string): Promise<string[]> {
|
|
118
|
+
try {
|
|
119
|
+
const entries = await readdir(controlDir, { withFileTypes: true });
|
|
120
|
+
return entries
|
|
121
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
|
|
122
|
+
.map((entry) => path.join(controlDir, entry.name));
|
|
123
|
+
} catch (error) {
|
|
124
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
125
|
+
if (code === "ENOENT") {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function loadDescriptors(
|
|
133
|
+
stateDir: string,
|
|
134
|
+
): Promise<Array<{ descriptor: PrivateClawSessionControlDescriptor; descriptorPath: string }>> {
|
|
135
|
+
const descriptorPaths = await listDescriptorPaths(resolvePrivateClawControlDir(stateDir));
|
|
136
|
+
const descriptors: Array<{
|
|
137
|
+
descriptor: PrivateClawSessionControlDescriptor;
|
|
138
|
+
descriptorPath: string;
|
|
139
|
+
}> = [];
|
|
140
|
+
for (const descriptorPath of descriptorPaths) {
|
|
141
|
+
try {
|
|
142
|
+
const descriptor = JSON.parse(
|
|
143
|
+
await readFile(descriptorPath, "utf8"),
|
|
144
|
+
) as unknown;
|
|
145
|
+
if (!isDescriptor(descriptor)) {
|
|
146
|
+
await rm(descriptorPath, { force: true });
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
descriptors.push({ descriptor, descriptorPath });
|
|
150
|
+
} catch {
|
|
151
|
+
await rm(descriptorPath, { force: true });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return descriptors;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function requestDescriptorJson<T>(
|
|
158
|
+
descriptor: PrivateClawSessionControlDescriptor,
|
|
159
|
+
pathname: string,
|
|
160
|
+
init?: {
|
|
161
|
+
method?: "GET" | "POST";
|
|
162
|
+
body?: unknown;
|
|
163
|
+
},
|
|
164
|
+
): Promise<T> {
|
|
165
|
+
const response = await fetch(
|
|
166
|
+
`http://${descriptor.host}:${descriptor.port}${pathname}`,
|
|
167
|
+
{
|
|
168
|
+
method: init?.method ?? "GET",
|
|
169
|
+
headers: {
|
|
170
|
+
authorization: `Bearer ${descriptor.token}`,
|
|
171
|
+
...(init?.body !== undefined
|
|
172
|
+
? { "content-type": "application/json; charset=utf-8" }
|
|
173
|
+
: {}),
|
|
174
|
+
},
|
|
175
|
+
...(init?.body !== undefined
|
|
176
|
+
? { body: JSON.stringify(init.body) }
|
|
177
|
+
: {}),
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
if (!response.ok) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Control request failed (${response.status} ${response.statusText})`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return (await response.json()) as T;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function formatHostKind(kind: PrivateClawControlHostKind): string {
|
|
191
|
+
switch (kind) {
|
|
192
|
+
case "plugin-service":
|
|
193
|
+
return "plugin-service";
|
|
194
|
+
case "pair-foreground":
|
|
195
|
+
return "pair-foreground";
|
|
196
|
+
case "pair-daemon":
|
|
197
|
+
return "pair-daemon";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function resolvePrivateClawStateDir(
|
|
202
|
+
stateDir: string = process.env.OPENCLAW_STATE_DIR ?? path.join(os.homedir(), ".openclaw"),
|
|
203
|
+
): string {
|
|
204
|
+
return stateDir;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function resolvePrivateClawControlDir(stateDir: string): string {
|
|
208
|
+
return path.join(resolvePrivateClawStateDir(stateDir), "privateclaw", "control");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function buildManagedSessionsReportLines(
|
|
212
|
+
listings: ReadonlyArray<PrivateClawDiscoveredSessionListing>,
|
|
213
|
+
): string[] {
|
|
214
|
+
const sessions = listings.flatMap((listing) =>
|
|
215
|
+
listing.sessions.map((session) => ({
|
|
216
|
+
host: listing.host,
|
|
217
|
+
session,
|
|
218
|
+
})),
|
|
219
|
+
);
|
|
220
|
+
if (sessions.length === 0) {
|
|
221
|
+
return [
|
|
222
|
+
formatBilingualInline(
|
|
223
|
+
"当前没有活动中的 PrivateClaw 会话。",
|
|
224
|
+
"No active PrivateClaw sessions.",
|
|
225
|
+
),
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const lines = [
|
|
230
|
+
formatBilingualInline(
|
|
231
|
+
`当前共有 ${sessions.length} 个活动中的 PrivateClaw 会话。`,
|
|
232
|
+
`Found ${sessions.length} active PrivateClaw sessions.`,
|
|
233
|
+
),
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
for (const { host, session } of sessions) {
|
|
237
|
+
lines.push(
|
|
238
|
+
`- ${session.sessionId} | type=${session.groupMode ? "group" : "single"} | participants=${session.participantCount} | state=${session.state} | expires=${session.expiresAt} | host=${formatHostKind(host.kind)}#${host.pid}${session.label ? ` | label=${JSON.stringify(session.label)}` : ""}`,
|
|
239
|
+
);
|
|
240
|
+
if (session.participants.length > 0) {
|
|
241
|
+
for (const participant of session.participants) {
|
|
242
|
+
lines.push(
|
|
243
|
+
` • ${participant.displayName} (${participant.appId})${participant.deviceLabel ? ` [${participant.deviceLabel}]` : ""}`,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return lines;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export class PrivateClawSessionControlServer {
|
|
253
|
+
private server:
|
|
254
|
+
| ReturnType<typeof createServer>
|
|
255
|
+
| undefined;
|
|
256
|
+
private descriptor: PrivateClawSessionControlDescriptor | undefined;
|
|
257
|
+
private descriptorPath: string | undefined;
|
|
258
|
+
|
|
259
|
+
constructor(
|
|
260
|
+
private readonly options: {
|
|
261
|
+
provider: PrivateClawSessionControlProvider;
|
|
262
|
+
stateDir: string;
|
|
263
|
+
kind: PrivateClawControlHostKind;
|
|
264
|
+
onLog?: (message: string) => void;
|
|
265
|
+
},
|
|
266
|
+
) {}
|
|
267
|
+
|
|
268
|
+
async start(): Promise<void> {
|
|
269
|
+
if (this.server) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
await mkdir(resolvePrivateClawControlDir(this.options.stateDir), {
|
|
274
|
+
recursive: true,
|
|
275
|
+
mode: 0o700,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const token = randomUUID();
|
|
279
|
+
const controlId = randomUUID();
|
|
280
|
+
const startedAt = new Date().toISOString();
|
|
281
|
+
|
|
282
|
+
this.server = createServer(async (request, response) => {
|
|
283
|
+
try {
|
|
284
|
+
if (readBearerToken(request) !== token) {
|
|
285
|
+
writeJson(response, 401, { error: "unauthorized" });
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
290
|
+
if (request.method === "GET" && url.pathname === "/healthz") {
|
|
291
|
+
writeJson(response, 200, { ok: true });
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (request.method === "GET" && url.pathname === "/sessions") {
|
|
295
|
+
writeJson(response, 200, {
|
|
296
|
+
host: {
|
|
297
|
+
controlId,
|
|
298
|
+
kind: this.options.kind,
|
|
299
|
+
pid: process.pid,
|
|
300
|
+
startedAt,
|
|
301
|
+
},
|
|
302
|
+
sessions: this.options.provider.listManagedSessions(),
|
|
303
|
+
});
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (
|
|
307
|
+
request.method === "POST" &&
|
|
308
|
+
url.pathname.startsWith("/sessions/") &&
|
|
309
|
+
url.pathname.endsWith("/kick")
|
|
310
|
+
) {
|
|
311
|
+
const sessionId = decodeURIComponent(
|
|
312
|
+
url.pathname.slice("/sessions/".length, -"/kick".length),
|
|
313
|
+
);
|
|
314
|
+
const body = (await readJsonBody(request)) as Record<string, unknown>;
|
|
315
|
+
const appId = typeof body.appId === "string" ? body.appId : "";
|
|
316
|
+
const reason =
|
|
317
|
+
typeof body.reason === "string" && body.reason.trim() !== ""
|
|
318
|
+
? body.reason
|
|
319
|
+
: undefined;
|
|
320
|
+
const participant = await this.options.provider.kickGroupParticipant(
|
|
321
|
+
sessionId,
|
|
322
|
+
appId,
|
|
323
|
+
reason,
|
|
324
|
+
);
|
|
325
|
+
writeJson(response, 200, {
|
|
326
|
+
sessionId,
|
|
327
|
+
participant,
|
|
328
|
+
} satisfies PrivateClawKickResult);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
writeJson(response, 404, { error: "not_found" });
|
|
333
|
+
} catch (error) {
|
|
334
|
+
const message =
|
|
335
|
+
error instanceof Error ? error.message : String(error);
|
|
336
|
+
this.options.onLog?.(
|
|
337
|
+
`[session-control] ${this.options.kind} request failed: ${message}`,
|
|
338
|
+
);
|
|
339
|
+
writeJson(response, 400, { error: message });
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
await new Promise<void>((resolve, reject) => {
|
|
344
|
+
this.server!.once("error", reject);
|
|
345
|
+
this.server!.listen(0, "127.0.0.1", () => resolve());
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
const address = this.server.address() as AddressInfo | null;
|
|
349
|
+
if (!address) {
|
|
350
|
+
throw new Error("PrivateClaw session control server failed to bind.");
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
this.descriptor = {
|
|
354
|
+
version: 1,
|
|
355
|
+
controlId,
|
|
356
|
+
kind: this.options.kind,
|
|
357
|
+
pid: process.pid,
|
|
358
|
+
host: "127.0.0.1",
|
|
359
|
+
port: address.port,
|
|
360
|
+
token,
|
|
361
|
+
startedAt,
|
|
362
|
+
};
|
|
363
|
+
this.descriptorPath = path.join(
|
|
364
|
+
resolvePrivateClawControlDir(this.options.stateDir),
|
|
365
|
+
`${this.options.kind}-${process.pid}-${controlId}.json`,
|
|
366
|
+
);
|
|
367
|
+
await writeFile(
|
|
368
|
+
this.descriptorPath,
|
|
369
|
+
JSON.stringify(this.descriptor, null, 2),
|
|
370
|
+
{ mode: 0o600 },
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
async stop(): Promise<void> {
|
|
375
|
+
if (this.server) {
|
|
376
|
+
await new Promise<void>((resolve, reject) => {
|
|
377
|
+
this.server!.close((error) => {
|
|
378
|
+
if (error) {
|
|
379
|
+
reject(error);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
resolve();
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
this.server = undefined;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (this.descriptorPath) {
|
|
389
|
+
await rm(this.descriptorPath, { force: true });
|
|
390
|
+
this.descriptorPath = undefined;
|
|
391
|
+
}
|
|
392
|
+
this.descriptor = undefined;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export async function listManagedSessionsFromStateDir(
|
|
397
|
+
stateDir: string,
|
|
398
|
+
): Promise<PrivateClawDiscoveredSessionListing[]> {
|
|
399
|
+
const descriptors = await loadDescriptors(stateDir);
|
|
400
|
+
const listings: PrivateClawDiscoveredSessionListing[] = [];
|
|
401
|
+
|
|
402
|
+
for (const { descriptor, descriptorPath } of descriptors) {
|
|
403
|
+
try {
|
|
404
|
+
const response = await requestDescriptorJson<{
|
|
405
|
+
host: PrivateClawDiscoveredSessionHost;
|
|
406
|
+
sessions: PrivateClawManagedSession[];
|
|
407
|
+
}>(descriptor, "/sessions");
|
|
408
|
+
listings.push({
|
|
409
|
+
host: response.host ?? toHostSummary(descriptor),
|
|
410
|
+
sessions: response.sessions ?? [],
|
|
411
|
+
});
|
|
412
|
+
} catch {
|
|
413
|
+
await rm(descriptorPath, { force: true });
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return listings.sort((left, right) =>
|
|
418
|
+
left.host.startedAt.localeCompare(right.host.startedAt),
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export async function kickManagedParticipantFromStateDir(params: {
|
|
423
|
+
stateDir: string;
|
|
424
|
+
sessionId: string;
|
|
425
|
+
appId: string;
|
|
426
|
+
reason?: string;
|
|
427
|
+
}): Promise<{
|
|
428
|
+
host: PrivateClawDiscoveredSessionHost;
|
|
429
|
+
session: PrivateClawManagedSession;
|
|
430
|
+
participant: {
|
|
431
|
+
appId: string;
|
|
432
|
+
displayName: string;
|
|
433
|
+
};
|
|
434
|
+
}> {
|
|
435
|
+
const listings = await listManagedSessionsFromStateDir(params.stateDir);
|
|
436
|
+
for (const listing of listings) {
|
|
437
|
+
const session = listing.sessions.find(
|
|
438
|
+
(candidate) => candidate.sessionId === params.sessionId,
|
|
439
|
+
);
|
|
440
|
+
if (!session) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const descriptors = await loadDescriptors(params.stateDir);
|
|
445
|
+
const descriptor = descriptors.find(
|
|
446
|
+
(candidate) => candidate.descriptor.controlId === listing.host.controlId,
|
|
447
|
+
);
|
|
448
|
+
if (!descriptor) {
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const result = await requestDescriptorJson<PrivateClawKickResult>(
|
|
453
|
+
descriptor.descriptor,
|
|
454
|
+
`/sessions/${encodeURIComponent(params.sessionId)}/kick`,
|
|
455
|
+
{
|
|
456
|
+
method: "POST",
|
|
457
|
+
body: {
|
|
458
|
+
appId: params.appId,
|
|
459
|
+
...(params.reason ? { reason: params.reason } : {}),
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
);
|
|
463
|
+
return {
|
|
464
|
+
host: listing.host,
|
|
465
|
+
session,
|
|
466
|
+
participant: result.participant,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
throw new Error(
|
|
471
|
+
`Could not find session ${params.sessionId} in ${resolvePrivateClawStateDir(params.stateDir)}.`,
|
|
472
|
+
);
|
|
473
|
+
}
|
package/src/text.ts
CHANGED
|
@@ -47,6 +47,16 @@ export const PRIVATECLAW_CLI_PAIR_DESCRIPTION = formatBilingualInline(
|
|
|
47
47
|
"Start a local PrivateClaw session and render the pairing QR code in the terminal.",
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
+
export const PRIVATECLAW_CLI_SESSIONS_DESCRIPTION = formatBilingualInline(
|
|
51
|
+
"列出当前活动中的 PrivateClaw 会话及参与者。",
|
|
52
|
+
"List the active PrivateClaw sessions and their participants.",
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const PRIVATECLAW_CLI_KICK_DESCRIPTION = formatBilingualInline(
|
|
56
|
+
"从群聊会话中移除指定参与者。",
|
|
57
|
+
"Remove a participant from a group session.",
|
|
58
|
+
);
|
|
59
|
+
|
|
50
60
|
export const PRIVATECLAW_CLI_TTL_OPTION_DESCRIPTION = formatBilingualInline(
|
|
51
61
|
"会话 TTL(毫秒)。",
|
|
52
62
|
"Session TTL in milliseconds.",
|
|
@@ -73,6 +83,11 @@ export const PRIVATECLAW_CLI_OPEN_OPTION_DESCRIPTION = formatBilingualInline(
|
|
|
73
83
|
"Open a local browser preview after generating the QR code.",
|
|
74
84
|
);
|
|
75
85
|
|
|
86
|
+
export const PRIVATECLAW_CLI_FOREGROUND_OPTION_DESCRIPTION = formatBilingualInline(
|
|
87
|
+
"保持当前命令在前台运行,直到会话结束或按 Ctrl+C;在支持的运行时里也可按 Ctrl+D 转入后台。",
|
|
88
|
+
"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.",
|
|
89
|
+
);
|
|
90
|
+
|
|
76
91
|
export const PRIVATECLAW_INVITE_URI_LABEL = formatBilingualInline(
|
|
77
92
|
"邀请链接",
|
|
78
93
|
"Invite URI",
|
|
@@ -88,6 +103,16 @@ export const PRIVATECLAW_WAITING_FOR_APP_MESSAGE = formatBilingualInline(
|
|
|
88
103
|
"Waiting for the PrivateClaw app to connect. Press Ctrl+C to stop.",
|
|
89
104
|
);
|
|
90
105
|
|
|
106
|
+
export const PRIVATECLAW_WAITING_FOR_APP_WITH_BACKGROUND_MESSAGE = formatBilingualInline(
|
|
107
|
+
"等待 PrivateClaw App 连接,按 Ctrl+C 停止,按 Ctrl+D 转入后台。",
|
|
108
|
+
"Waiting for the PrivateClaw app to connect. Press Ctrl+C to stop or Ctrl+D to move it into the background.",
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
export const PRIVATECLAW_SESSION_ENDED_MESSAGE = formatBilingualInline(
|
|
112
|
+
"PrivateClaw 会话已结束。",
|
|
113
|
+
"The PrivateClaw session has ended.",
|
|
114
|
+
);
|
|
115
|
+
|
|
91
116
|
export function buildPrivateClawShutdownMessage(signal: string): string {
|
|
92
117
|
return `[privateclaw-provider] ${formatBilingualInline(
|
|
93
118
|
`收到 ${signal},正在关闭`,
|
|
@@ -95,6 +120,15 @@ export function buildPrivateClawShutdownMessage(signal: string): string {
|
|
|
95
120
|
)}`;
|
|
96
121
|
}
|
|
97
122
|
|
|
123
|
+
export function buildPrivateClawBackgroundHandoffFailureMessage(
|
|
124
|
+
details: string,
|
|
125
|
+
): string {
|
|
126
|
+
return `[privateclaw-provider] ${formatBilingualInline(
|
|
127
|
+
`转入后台失败:${details}`,
|
|
128
|
+
`failed to move the session into the background: ${details}`,
|
|
129
|
+
)}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
98
132
|
export function buildPrivateClawCommandErrorMessage(details: string): string {
|
|
99
133
|
return formatBilingualInline(
|
|
100
134
|
`创建 PrivateClaw 会话失败:${details}`,
|
package/src/types.ts
CHANGED
|
@@ -45,6 +45,7 @@ export interface PrivateClawProviderOptions {
|
|
|
45
45
|
providerWsUrl: string;
|
|
46
46
|
appWsUrl: string;
|
|
47
47
|
bridge: PrivateClawAgentBridge;
|
|
48
|
+
providerId?: string;
|
|
48
49
|
defaultTtlMs?: number;
|
|
49
50
|
providerLabel?: string;
|
|
50
51
|
welcomeMessage?: string;
|
|
@@ -56,6 +57,17 @@ export interface ProviderParticipantState extends PrivateClawParticipant {
|
|
|
56
57
|
lastSeenAt: string;
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
export interface PrivateClawManagedSession {
|
|
61
|
+
sessionId: string;
|
|
62
|
+
expiresAt: string;
|
|
63
|
+
providerLabel?: string;
|
|
64
|
+
label?: string;
|
|
65
|
+
groupMode: boolean;
|
|
66
|
+
participantCount: number;
|
|
67
|
+
participants: PrivateClawParticipant[];
|
|
68
|
+
state: "awaiting_hello" | "active";
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
export interface PrivateClawInviteBundle {
|
|
60
72
|
invite: PrivateClawInvite;
|
|
61
73
|
inviteUri: string;
|
|
@@ -67,10 +79,12 @@ export interface PrivateClawInviteBundle {
|
|
|
67
79
|
|
|
68
80
|
export interface ProviderSessionState {
|
|
69
81
|
invite: PrivateClawInvite;
|
|
82
|
+
label?: string;
|
|
70
83
|
history: PrivateClawConversationTurn[];
|
|
71
84
|
groupMode: boolean;
|
|
72
85
|
botMuted: boolean;
|
|
73
86
|
participants: Map<string, ProviderParticipantState>;
|
|
87
|
+
removedParticipantAppIds: Set<string>;
|
|
74
88
|
state: "awaiting_hello" | "active";
|
|
75
89
|
pendingRenewal?: {
|
|
76
90
|
expiresAt: string;
|
|
@@ -79,3 +93,24 @@ export interface ProviderSessionState {
|
|
|
79
93
|
renewalReminderSentAt?: string;
|
|
80
94
|
renewalReminderTimer?: ReturnType<typeof setTimeout>;
|
|
81
95
|
}
|
|
96
|
+
|
|
97
|
+
export interface PrivateClawProviderSessionHandoff {
|
|
98
|
+
invite: PrivateClawInvite;
|
|
99
|
+
label?: string;
|
|
100
|
+
history: PrivateClawConversationTurn[];
|
|
101
|
+
groupMode: boolean;
|
|
102
|
+
botMuted: boolean;
|
|
103
|
+
participants: ProviderParticipantState[];
|
|
104
|
+
removedParticipantAppIds: string[];
|
|
105
|
+
state: "awaiting_hello" | "active";
|
|
106
|
+
pendingRenewal?: {
|
|
107
|
+
expiresAt: string;
|
|
108
|
+
sentAt: string;
|
|
109
|
+
};
|
|
110
|
+
renewalReminderSentAt?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface PrivateClawProviderHandoffState {
|
|
114
|
+
providerId: string;
|
|
115
|
+
sessions: PrivateClawProviderSessionHandoff[];
|
|
116
|
+
}
|