@privateclaw/privateclaw 0.1.0 → 0.1.2
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 +103 -8
- package/dist/bridges/openclaw-agent-bridge.d.ts +5 -0
- package/dist/bridges/openclaw-agent-bridge.js +228 -15
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/cli.js +11 -19
- package/dist/cli.js.map +1 -1
- package/dist/compat/openclaw.d.ts +18 -1
- package/dist/compat/openclaw.js +3 -1
- package/dist/compat/openclaw.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/openclaw-command-discovery.d.ts +1 -0
- package/dist/openclaw-command-discovery.js +67 -14
- package/dist/openclaw-command-discovery.js.map +1 -1
- package/dist/openclaw-plugin.js +90 -15
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/pair-session.d.ts +12 -0
- package/dist/pair-session.js +63 -0
- package/dist/pair-session.js.map +1 -0
- package/dist/provider.d.ts +22 -1
- package/dist/provider.js +625 -60
- package/dist/provider.js.map +1 -1
- package/dist/qr-options.d.ts +5 -0
- package/dist/qr-options.js +6 -0
- package/dist/qr-options.js.map +1 -0
- package/dist/relay-defaults.d.ts +1 -0
- package/dist/relay-defaults.js +2 -0
- package/dist/relay-defaults.js.map +1 -0
- package/dist/relay-provider-client.d.ts +2 -2
- package/dist/relay-provider-client.js +9 -3
- package/dist/relay-provider-client.js.map +1 -1
- package/dist/text.d.ts +22 -0
- package/dist/text.js +32 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +14 -1
- package/openclaw.plugin.json +3 -2
- package/package.json +1 -1
- package/src/bridges/openclaw-agent-bridge.test.ts +141 -0
- package/src/bridges/openclaw-agent-bridge.ts +302 -16
- package/src/cli.ts +14 -22
- package/src/compat/openclaw.ts +30 -1
- package/src/index.ts +1 -0
- package/src/openclaw-command-discovery.test.ts +108 -0
- package/src/openclaw-command-discovery.ts +119 -19
- package/src/openclaw-plugin.test.ts +139 -0
- package/src/openclaw-plugin.ts +137 -15
- package/src/pair-session.ts +100 -0
- package/src/provider.test.ts +714 -1
- package/src/provider.ts +952 -60
- package/src/qr-options.ts +5 -0
- package/src/relay-defaults.ts +1 -0
- package/src/relay-provider-client.ts +13 -2
- package/src/text.ts +108 -0
- package/src/types.ts +15 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_RELAY_BASE_URL = "https://relay.privateclaw.us";
|
|
@@ -263,6 +263,7 @@ export class RelayProviderClient {
|
|
|
263
263
|
async createSession(
|
|
264
264
|
ttlMs?: number,
|
|
265
265
|
label?: string,
|
|
266
|
+
groupMode?: boolean,
|
|
266
267
|
): Promise<{ sessionId: string; expiresAt: string }> {
|
|
267
268
|
await this.connect();
|
|
268
269
|
|
|
@@ -274,6 +275,7 @@ export class RelayProviderClient {
|
|
|
274
275
|
requestId,
|
|
275
276
|
...(ttlMs ? { ttlMs } : {}),
|
|
276
277
|
...(label ? { label } : {}),
|
|
278
|
+
...(typeof groupMode === "boolean" ? { groupMode } : {}),
|
|
277
279
|
});
|
|
278
280
|
});
|
|
279
281
|
}
|
|
@@ -296,9 +298,18 @@ export class RelayProviderClient {
|
|
|
296
298
|
});
|
|
297
299
|
}
|
|
298
300
|
|
|
299
|
-
async sendFrame(
|
|
301
|
+
async sendFrame(
|
|
302
|
+
sessionId: string,
|
|
303
|
+
envelope: EncryptedEnvelope,
|
|
304
|
+
targetAppId?: string,
|
|
305
|
+
): Promise<void> {
|
|
300
306
|
await this.connect();
|
|
301
|
-
this.send({
|
|
307
|
+
this.send({
|
|
308
|
+
type: "provider:frame",
|
|
309
|
+
sessionId,
|
|
310
|
+
envelope,
|
|
311
|
+
...(targetAppId ? { targetAppId } : {}),
|
|
312
|
+
});
|
|
302
313
|
}
|
|
303
314
|
|
|
304
315
|
async closeSession(sessionId: string, reason?: string): Promise<void> {
|
package/src/text.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export function formatBilingualText(chinese: string, english: string): string {
|
|
2
|
+
return `${chinese}\n${english}`;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function formatBilingualInline(
|
|
6
|
+
chinese: string,
|
|
7
|
+
english: string,
|
|
8
|
+
): string {
|
|
9
|
+
return `${chinese} / ${english}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function buildInviteAnnouncementText(params: {
|
|
13
|
+
sessionId: string;
|
|
14
|
+
expiresAt: string;
|
|
15
|
+
groupMode: boolean;
|
|
16
|
+
}): string {
|
|
17
|
+
if (params.groupMode) {
|
|
18
|
+
return formatBilingualText(
|
|
19
|
+
`PrivateClaw 群聊会话 ${params.sessionId} 已就绪,有效期至 ${params.expiresAt}。请将此二维码或邀请链接分享给所有需要加入这场端到端加密群聊的设备。`,
|
|
20
|
+
`PrivateClaw group session ${params.sessionId} is ready until ${params.expiresAt}. Share this QR code or invite link with every app that should join the end-to-end encrypted group chat.`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return formatBilingualText(
|
|
25
|
+
`PrivateClaw 会话 ${params.sessionId} 已就绪,有效期至 ${params.expiresAt}。请使用 PrivateClaw App 扫描二维码,或粘贴邀请链接完成连接。`,
|
|
26
|
+
`PrivateClaw session ${params.sessionId} is ready until ${params.expiresAt}. Scan the QR code or paste the invite link into the PrivateClaw app to connect.`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const PRIVATECLAW_PLUGIN_DESCRIPTION = formatBilingualInline(
|
|
31
|
+
"OpenClaw 的一次性端到端加密 PrivateClaw 会话插件。",
|
|
32
|
+
"Ephemeral end-to-end encrypted PrivateClaw session plugin for OpenClaw.",
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export const PRIVATECLAW_COMMAND_DESCRIPTION = formatBilingualInline(
|
|
36
|
+
"创建一次性加密的 PrivateClaw 会话二维码;传入 `group` 可启用群聊模式。",
|
|
37
|
+
"Create a one-time encrypted PrivateClaw session QR code; pass `group` to enable group chat.",
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const PRIVATECLAW_CLI_ROOT_DESCRIPTION = formatBilingualInline(
|
|
41
|
+
"PrivateClaw 本地配对与会话工具。",
|
|
42
|
+
"PrivateClaw local pairing and session utilities.",
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export const PRIVATECLAW_CLI_PAIR_DESCRIPTION = formatBilingualInline(
|
|
46
|
+
"启动本地 PrivateClaw 会话,并在终端中渲染配对二维码。",
|
|
47
|
+
"Start a local PrivateClaw session and render the pairing QR code in the terminal.",
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const PRIVATECLAW_CLI_TTL_OPTION_DESCRIPTION = formatBilingualInline(
|
|
51
|
+
"会话 TTL(毫秒)。",
|
|
52
|
+
"Session TTL in milliseconds.",
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const PRIVATECLAW_CLI_LABEL_OPTION_DESCRIPTION = formatBilingualInline(
|
|
56
|
+
"可选的中继会话标签。",
|
|
57
|
+
"Optional relay session label.",
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export const PRIVATECLAW_CLI_GROUP_OPTION_DESCRIPTION = formatBilingualInline(
|
|
61
|
+
"允许多个 PrivateClaw 客户端加入同一个会话。",
|
|
62
|
+
"Allow multiple PrivateClaw app clients to join the same session.",
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
export const PRIVATECLAW_CLI_PRINT_ONLY_OPTION_DESCRIPTION =
|
|
66
|
+
formatBilingualInline(
|
|
67
|
+
"仅打印邀请信息和二维码,然后立即退出。",
|
|
68
|
+
"Print the invite and QR code, then exit immediately.",
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
export const PRIVATECLAW_INVITE_URI_LABEL = formatBilingualInline(
|
|
72
|
+
"邀请链接",
|
|
73
|
+
"Invite URI",
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
export const PRIVATECLAW_WAITING_FOR_APP_MESSAGE = formatBilingualInline(
|
|
77
|
+
"等待 PrivateClaw App 连接,按 Ctrl+C 停止。",
|
|
78
|
+
"Waiting for the PrivateClaw app to connect. Press Ctrl+C to stop.",
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
export function buildPrivateClawShutdownMessage(signal: string): string {
|
|
82
|
+
return `[privateclaw-provider] ${formatBilingualInline(
|
|
83
|
+
`收到 ${signal},正在关闭`,
|
|
84
|
+
`received ${signal}, shutting down`,
|
|
85
|
+
)}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function buildPrivateClawCommandErrorMessage(details: string): string {
|
|
89
|
+
return formatBilingualInline(
|
|
90
|
+
`创建 PrivateClaw 会话失败:${details}`,
|
|
91
|
+
`Failed to create a PrivateClaw session: ${details}`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const PRIVATECLAW_RENEW_SESSION_DESCRIPTION = formatBilingualInline(
|
|
96
|
+
"轮换当前 PrivateClaw 会话密钥,并将当前会话延长 8 小时。",
|
|
97
|
+
"Rotate the current PrivateClaw session key and extend this session by 8 hours.",
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
export const PRIVATECLAW_MUTE_BOT_DESCRIPTION = formatBilingualInline(
|
|
101
|
+
"在当前群聊中暂停机器人参与回复。",
|
|
102
|
+
"Pause bot replies in this group chat.",
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
export const PRIVATECLAW_UNMUTE_BOT_DESCRIPTION = formatBilingualInline(
|
|
106
|
+
"在当前群聊中恢复机器人参与回复。",
|
|
107
|
+
"Resume bot replies in this group chat.",
|
|
108
|
+
);
|
package/src/types.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
PrivateClawAttachment,
|
|
3
3
|
PrivateClawInvite,
|
|
4
|
+
PrivateClawParticipant,
|
|
4
5
|
PrivateClawSlashCommand,
|
|
5
6
|
} from "@privateclaw/protocol";
|
|
6
7
|
|
|
7
8
|
export interface PrivateClawConversationTurn {
|
|
9
|
+
messageId: string;
|
|
8
10
|
role: "user" | "assistant" | "system";
|
|
9
11
|
text: string;
|
|
10
12
|
sentAt: string;
|
|
13
|
+
appId?: string;
|
|
14
|
+
participantLabel?: string;
|
|
15
|
+
replyTo?: string;
|
|
16
|
+
severity?: "info" | "error";
|
|
11
17
|
attachments?: PrivateClawAttachment[];
|
|
12
18
|
}
|
|
13
19
|
|
|
@@ -41,6 +47,10 @@ export interface PrivateClawProviderOptions {
|
|
|
41
47
|
onLog?: (message: string) => void;
|
|
42
48
|
}
|
|
43
49
|
|
|
50
|
+
export interface ProviderParticipantState extends PrivateClawParticipant {
|
|
51
|
+
lastSeenAt: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
44
54
|
export interface PrivateClawInviteBundle {
|
|
45
55
|
invite: PrivateClawInvite;
|
|
46
56
|
inviteUri: string;
|
|
@@ -52,9 +62,14 @@ export interface PrivateClawInviteBundle {
|
|
|
52
62
|
export interface ProviderSessionState {
|
|
53
63
|
invite: PrivateClawInvite;
|
|
54
64
|
history: PrivateClawConversationTurn[];
|
|
65
|
+
groupMode: boolean;
|
|
66
|
+
botMuted: boolean;
|
|
67
|
+
participants: Map<string, ProviderParticipantState>;
|
|
55
68
|
state: "awaiting_hello" | "active";
|
|
56
69
|
pendingRenewal?: {
|
|
57
70
|
expiresAt: string;
|
|
58
71
|
sentAt: string;
|
|
59
72
|
};
|
|
73
|
+
renewalReminderSentAt?: string;
|
|
74
|
+
renewalReminderTimer?: ReturnType<typeof setTimeout>;
|
|
60
75
|
}
|