@privateclaw/privateclaw 0.1.23 → 0.1.25
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 +13 -0
- package/dist/cli.js +24 -0
- package/dist/cli.js.map +1 -1
- package/dist/compat/openclaw.d.ts +14 -0
- package/dist/compat/openclaw.js +14 -0
- package/dist/compat/openclaw.js.map +1 -1
- package/dist/openclaw-plugin.d.ts +3 -0
- package/dist/openclaw-plugin.js +35 -0
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/provider.d.ts +15 -0
- package/dist/provider.js +327 -0
- package/dist/provider.js.map +1 -1
- package/dist/relay-provider-client.d.ts +4 -0
- package/dist/relay-provider-client.js +73 -27
- package/dist/relay-provider-client.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/openclaw.plugin.json +15 -1
- package/package.json +1 -1
- package/src/cli.ts +33 -0
- package/src/compat/openclaw.ts +15 -0
- package/src/openclaw-plugin.test.ts +3 -0
- package/src/openclaw-plugin.ts +46 -0
- package/src/provider.test.ts +427 -1
- package/src/provider.ts +419 -0
- package/src/relay-provider-client.test.ts +155 -0
- package/src/relay-provider-client.ts +115 -33
- package/src/types.ts +13 -0
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "privateclaw",
|
|
3
3
|
"name": "PrivateClaw",
|
|
4
4
|
"description": "Ephemeral end-to-end encrypted private session plugin for OpenClaw.",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.25",
|
|
6
6
|
"configSchema": {
|
|
7
7
|
"type": "object",
|
|
8
8
|
"additionalProperties": false,
|
|
@@ -21,6 +21,20 @@
|
|
|
21
21
|
"type": "string",
|
|
22
22
|
"description": "Encrypted welcome message sent to the client after handshake."
|
|
23
23
|
},
|
|
24
|
+
"botMode": {
|
|
25
|
+
"type": "boolean",
|
|
26
|
+
"description": "Enable proactive bot-mode group replies: greet silent joiners after 10 minutes and re-engage quiet groups after 20 minutes."
|
|
27
|
+
},
|
|
28
|
+
"botModeSilentJoinDelayMs": {
|
|
29
|
+
"type": "number",
|
|
30
|
+
"description": "Optional override for the silent-join proactive greeting delay in milliseconds.",
|
|
31
|
+
"minimum": 0
|
|
32
|
+
},
|
|
33
|
+
"botModeIdleDelayMs": {
|
|
34
|
+
"type": "number",
|
|
35
|
+
"description": "Optional override for the quiet-group proactive re-engagement delay in milliseconds.",
|
|
36
|
+
"minimum": 0
|
|
37
|
+
},
|
|
24
38
|
"providerLabel": {
|
|
25
39
|
"type": "string",
|
|
26
40
|
"description": "Label rendered into the invite payload and QR metadata."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privateclaw/privateclaw",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
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",
|
package/src/cli.ts
CHANGED
|
@@ -75,6 +75,22 @@ function parsePositiveInteger(value: string | undefined, fallback: number): numb
|
|
|
75
75
|
return parsed;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
function parseNonNegativeInteger(
|
|
79
|
+
value: string | undefined,
|
|
80
|
+
fallback: number,
|
|
81
|
+
): number {
|
|
82
|
+
if (!value || value.trim() === "") {
|
|
83
|
+
return fallback;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const parsed = Number.parseInt(value, 10);
|
|
87
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
88
|
+
throw new Error(`Expected a non-negative integer, received: ${value}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return parsed;
|
|
92
|
+
}
|
|
93
|
+
|
|
78
94
|
function parseBooleanFlag(value: string | undefined): boolean {
|
|
79
95
|
return value != null && /^(1|true|yes|on)$/i.test(value.trim());
|
|
80
96
|
}
|
|
@@ -216,6 +232,16 @@ function createProvider(params?: {
|
|
|
216
232
|
process.env.PRIVATECLAW_SESSION_TTL_MS,
|
|
217
233
|
DEFAULT_SESSION_TTL_MS,
|
|
218
234
|
);
|
|
235
|
+
const botMode = parseBooleanFlag(process.env.PRIVATECLAW_BOT_MODE);
|
|
236
|
+
const botModeSilentJoinDelayMs = process.env.PRIVATECLAW_BOT_MODE_SILENT_JOIN_DELAY_MS
|
|
237
|
+
? parseNonNegativeInteger(
|
|
238
|
+
process.env.PRIVATECLAW_BOT_MODE_SILENT_JOIN_DELAY_MS,
|
|
239
|
+
0,
|
|
240
|
+
)
|
|
241
|
+
: undefined;
|
|
242
|
+
const botModeIdleDelayMs = process.env.PRIVATECLAW_BOT_MODE_IDLE_DELAY_MS
|
|
243
|
+
? parseNonNegativeInteger(process.env.PRIVATECLAW_BOT_MODE_IDLE_DELAY_MS, 0)
|
|
244
|
+
: undefined;
|
|
219
245
|
const providerLabel =
|
|
220
246
|
process.env.PRIVATECLAW_PROVIDER_LABEL?.trim() || "PrivateClaw";
|
|
221
247
|
const welcomeMessage = process.env.PRIVATECLAW_WELCOME_MESSAGE?.trim();
|
|
@@ -230,6 +256,13 @@ function createProvider(params?: {
|
|
|
230
256
|
defaultTtlMs: ttlMs,
|
|
231
257
|
providerLabel,
|
|
232
258
|
...(verboseController ? { verboseController } : {}),
|
|
259
|
+
...(botMode ? { botMode: true } : {}),
|
|
260
|
+
...(typeof botModeSilentJoinDelayMs === "number"
|
|
261
|
+
? { botModeSilentJoinDelayMs }
|
|
262
|
+
: {}),
|
|
263
|
+
...(typeof botModeIdleDelayMs === "number"
|
|
264
|
+
? { botModeIdleDelayMs }
|
|
265
|
+
: {}),
|
|
233
266
|
commandsProvider: async () => {
|
|
234
267
|
try {
|
|
235
268
|
return await loadAvailableOpenClawCommands();
|
package/src/compat/openclaw.ts
CHANGED
|
@@ -18,6 +18,21 @@ export const privateClawConfigSchema = {
|
|
|
18
18
|
type: "string",
|
|
19
19
|
description: "Encrypted welcome message sent to the client after handshake.",
|
|
20
20
|
},
|
|
21
|
+
botMode: {
|
|
22
|
+
type: "boolean",
|
|
23
|
+
description:
|
|
24
|
+
"Enable proactive bot-mode group replies: greet silent joiners after 10 minutes and re-engage quiet groups after 20 minutes.",
|
|
25
|
+
},
|
|
26
|
+
botModeSilentJoinDelayMs: {
|
|
27
|
+
type: "number",
|
|
28
|
+
description: "Optional override for the silent-join proactive greeting delay in milliseconds.",
|
|
29
|
+
minimum: 0,
|
|
30
|
+
},
|
|
31
|
+
botModeIdleDelayMs: {
|
|
32
|
+
type: "number",
|
|
33
|
+
description: "Optional override for the quiet-group proactive re-engagement delay in milliseconds.",
|
|
34
|
+
minimum: 0,
|
|
35
|
+
},
|
|
21
36
|
providerLabel: {
|
|
22
37
|
type: "string",
|
|
23
38
|
description: "Label rendered into the invite payload and QR metadata.",
|
|
@@ -110,6 +110,9 @@ test("privateclaw schema advertises the public relay default", () => {
|
|
|
110
110
|
privateClawConfigSchema.properties.relayBaseUrl.default,
|
|
111
111
|
DEFAULT_RELAY_BASE_URL,
|
|
112
112
|
);
|
|
113
|
+
assert.equal(privateClawConfigSchema.properties.botMode.type, "boolean");
|
|
114
|
+
assert.equal(privateClawConfigSchema.properties.botModeSilentJoinDelayMs.minimum, 0);
|
|
115
|
+
assert.equal(privateClawConfigSchema.properties.botModeIdleDelayMs.minimum, 0);
|
|
113
116
|
});
|
|
114
117
|
|
|
115
118
|
test("privateclaw command writes QR media into the OpenClaw state media directory", async (t) => {
|
package/src/openclaw-plugin.ts
CHANGED
|
@@ -90,6 +90,9 @@ export interface PrivateClawPluginConfig {
|
|
|
90
90
|
relayBaseUrl?: string;
|
|
91
91
|
sessionTtlMs?: number;
|
|
92
92
|
welcomeMessage?: string;
|
|
93
|
+
botMode?: boolean;
|
|
94
|
+
botModeSilentJoinDelayMs?: number;
|
|
95
|
+
botModeIdleDelayMs?: number;
|
|
93
96
|
providerLabel?: string;
|
|
94
97
|
webhookUrl?: string;
|
|
95
98
|
webhookToken?: string;
|
|
@@ -114,6 +117,9 @@ interface ResolvedPrivateClawPluginConfig {
|
|
|
114
117
|
providerLabel: string;
|
|
115
118
|
sessionTtlMs?: number;
|
|
116
119
|
welcomeMessage?: string;
|
|
120
|
+
botMode?: boolean;
|
|
121
|
+
botModeSilentJoinDelayMs?: number;
|
|
122
|
+
botModeIdleDelayMs?: number;
|
|
117
123
|
webhookUrl?: string;
|
|
118
124
|
webhookToken?: string;
|
|
119
125
|
echoPrefix?: string;
|
|
@@ -259,6 +265,15 @@ function resolvePluginConfig(
|
|
|
259
265
|
const welcomeMessage =
|
|
260
266
|
readString(pluginConfig?.welcomeMessage) ??
|
|
261
267
|
readString(process.env.PRIVATECLAW_WELCOME_MESSAGE);
|
|
268
|
+
const botMode =
|
|
269
|
+
readBoolean(pluginConfig?.botMode) ??
|
|
270
|
+
readBoolean(process.env.PRIVATECLAW_BOT_MODE);
|
|
271
|
+
const botModeSilentJoinDelayMs =
|
|
272
|
+
readNumber(pluginConfig?.botModeSilentJoinDelayMs) ??
|
|
273
|
+
readNumber(process.env.PRIVATECLAW_BOT_MODE_SILENT_JOIN_DELAY_MS);
|
|
274
|
+
const botModeIdleDelayMs =
|
|
275
|
+
readNumber(pluginConfig?.botModeIdleDelayMs) ??
|
|
276
|
+
readNumber(process.env.PRIVATECLAW_BOT_MODE_IDLE_DELAY_MS);
|
|
262
277
|
const webhookUrl =
|
|
263
278
|
readString(pluginConfig?.webhookUrl) ??
|
|
264
279
|
readString(process.env.PRIVATECLAW_WEBHOOK_URL);
|
|
@@ -305,6 +320,11 @@ function resolvePluginConfig(
|
|
|
305
320
|
DEFAULT_PROVIDER_LABEL,
|
|
306
321
|
...(typeof sessionTtlMs === "number" ? { sessionTtlMs } : {}),
|
|
307
322
|
...(welcomeMessage ? { welcomeMessage } : {}),
|
|
323
|
+
...(typeof botMode === "boolean" ? { botMode } : {}),
|
|
324
|
+
...(typeof botModeSilentJoinDelayMs === "number"
|
|
325
|
+
? { botModeSilentJoinDelayMs }
|
|
326
|
+
: {}),
|
|
327
|
+
...(typeof botModeIdleDelayMs === "number" ? { botModeIdleDelayMs } : {}),
|
|
308
328
|
...(webhookUrl ? { webhookUrl } : {}),
|
|
309
329
|
...(webhookToken ? { webhookToken } : {}),
|
|
310
330
|
...(echoPrefix ? { echoPrefix } : {}),
|
|
@@ -545,6 +565,15 @@ function buildProviderOptions(
|
|
|
545
565
|
}
|
|
546
566
|
},
|
|
547
567
|
...(pluginConfig.welcomeMessage ? { welcomeMessage: pluginConfig.welcomeMessage } : {}),
|
|
568
|
+
...(typeof pluginConfig.botMode === "boolean"
|
|
569
|
+
? { botMode: pluginConfig.botMode }
|
|
570
|
+
: {}),
|
|
571
|
+
...(typeof pluginConfig.botModeSilentJoinDelayMs === "number"
|
|
572
|
+
? { botModeSilentJoinDelayMs: pluginConfig.botModeSilentJoinDelayMs }
|
|
573
|
+
: {}),
|
|
574
|
+
...(typeof pluginConfig.botModeIdleDelayMs === "number"
|
|
575
|
+
? { botModeIdleDelayMs: pluginConfig.botModeIdleDelayMs }
|
|
576
|
+
: {}),
|
|
548
577
|
verboseController,
|
|
549
578
|
onLog: log,
|
|
550
579
|
},
|
|
@@ -568,6 +597,23 @@ function buildDaemonEnvFromPluginConfig(
|
|
|
568
597
|
...(pluginConfig.welcomeMessage
|
|
569
598
|
? { PRIVATECLAW_WELCOME_MESSAGE: pluginConfig.welcomeMessage }
|
|
570
599
|
: {}),
|
|
600
|
+
...(typeof pluginConfig.botMode === "boolean"
|
|
601
|
+
? {
|
|
602
|
+
PRIVATECLAW_BOT_MODE: pluginConfig.botMode ? "true" : "false",
|
|
603
|
+
}
|
|
604
|
+
: {}),
|
|
605
|
+
...(typeof pluginConfig.botModeSilentJoinDelayMs === "number"
|
|
606
|
+
? {
|
|
607
|
+
PRIVATECLAW_BOT_MODE_SILENT_JOIN_DELAY_MS: String(
|
|
608
|
+
pluginConfig.botModeSilentJoinDelayMs,
|
|
609
|
+
),
|
|
610
|
+
}
|
|
611
|
+
: {}),
|
|
612
|
+
...(typeof pluginConfig.botModeIdleDelayMs === "number"
|
|
613
|
+
? {
|
|
614
|
+
PRIVATECLAW_BOT_MODE_IDLE_DELAY_MS: String(pluginConfig.botModeIdleDelayMs),
|
|
615
|
+
}
|
|
616
|
+
: {}),
|
|
571
617
|
...(pluginConfig.webhookUrl
|
|
572
618
|
? { PRIVATECLAW_WEBHOOK_URL: pluginConfig.webhookUrl }
|
|
573
619
|
: {}),
|
package/src/provider.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import test from "node:test";
|
|
2
|
+
import test, { type TestContext } from "node:test";
|
|
3
3
|
import {
|
|
4
4
|
decodeInviteString,
|
|
5
5
|
decryptPayload,
|
|
@@ -115,6 +115,76 @@ async function nextRelayPayload(
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
async function connectGroupApp(params: {
|
|
119
|
+
invite: ReturnType<typeof decodeInviteString>;
|
|
120
|
+
appId: string;
|
|
121
|
+
displayName: string;
|
|
122
|
+
deviceLabel?: string;
|
|
123
|
+
expectedFrameCount?: number;
|
|
124
|
+
}): Promise<WebSocket> {
|
|
125
|
+
const appUrl = new URL(params.invite.appWsUrl);
|
|
126
|
+
appUrl.searchParams.set("appId", params.appId);
|
|
127
|
+
const socket = new WebSocket(appUrl.toString());
|
|
128
|
+
const attached = nextMessage(socket);
|
|
129
|
+
await waitForOpen(socket);
|
|
130
|
+
assert.equal((await attached).type, "relay:attached");
|
|
131
|
+
const initialFrames = nextMessages(socket, params.expectedFrameCount ?? 3);
|
|
132
|
+
socket.send(
|
|
133
|
+
JSON.stringify({
|
|
134
|
+
type: "app:frame",
|
|
135
|
+
envelope: encryptPayload({
|
|
136
|
+
sessionId: params.invite.sessionId,
|
|
137
|
+
sessionKey: params.invite.sessionKey,
|
|
138
|
+
payload: {
|
|
139
|
+
kind: "client_hello",
|
|
140
|
+
appId: params.appId,
|
|
141
|
+
displayName: params.displayName,
|
|
142
|
+
appVersion: "flutter-test",
|
|
143
|
+
deviceLabel: params.deviceLabel ?? `${params.displayName} device`,
|
|
144
|
+
sentAt: new Date().toISOString(),
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
await initialFrames;
|
|
150
|
+
return socket;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function createGroupBotModeHarness(
|
|
154
|
+
t: TestContext,
|
|
155
|
+
bridge: { handleUserMessage(params: { message: string }): Promise<string> },
|
|
156
|
+
providerOptions?: Partial<ConstructorParameters<typeof PrivateClawProvider>[0]>,
|
|
157
|
+
): Promise<{ invite: ReturnType<typeof decodeInviteString>; provider: PrivateClawProvider }> {
|
|
158
|
+
const relay = createRelayServer({
|
|
159
|
+
host: "127.0.0.1",
|
|
160
|
+
port: 0,
|
|
161
|
+
sessionTtlMs: 60_000,
|
|
162
|
+
frameCacheSize: 8,
|
|
163
|
+
});
|
|
164
|
+
const { port } = await relay.start();
|
|
165
|
+
t.after(async () => {
|
|
166
|
+
await relay.stop();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const provider = new PrivateClawProvider({
|
|
170
|
+
providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
|
|
171
|
+
appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
|
|
172
|
+
bridge,
|
|
173
|
+
defaultTtlMs: DEFAULT_SESSION_TTL_MS,
|
|
174
|
+
...providerOptions,
|
|
175
|
+
});
|
|
176
|
+
await provider.connect();
|
|
177
|
+
t.after(async () => {
|
|
178
|
+
await provider.dispose();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const inviteBundle = await provider.createInviteBundle({ groupMode: true });
|
|
182
|
+
return {
|
|
183
|
+
provider,
|
|
184
|
+
invite: decodeInviteString(inviteBundle.inviteUri),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
118
188
|
function decryptRelayPayload(
|
|
119
189
|
frame: Record<string, unknown>,
|
|
120
190
|
params: { sessionId: string; sessionKey: string },
|
|
@@ -157,6 +227,27 @@ class HistoryRecordingBridge {
|
|
|
157
227
|
}
|
|
158
228
|
}
|
|
159
229
|
|
|
230
|
+
class BotModeBridge {
|
|
231
|
+
readonly prompts: string[] = [];
|
|
232
|
+
readonly promptKinds: Array<"silent_join" | "idle_group" | "user"> = [];
|
|
233
|
+
|
|
234
|
+
async handleUserMessage(params: {
|
|
235
|
+
message: string;
|
|
236
|
+
}): Promise<string> {
|
|
237
|
+
this.prompts.push(params.message);
|
|
238
|
+
if (params.message.includes("joined this PrivateClaw group chat")) {
|
|
239
|
+
this.promptKinds.push("silent_join");
|
|
240
|
+
return "Bot mode hello";
|
|
241
|
+
}
|
|
242
|
+
if (params.message.includes("has had no new message")) {
|
|
243
|
+
this.promptKinds.push("idle_group");
|
|
244
|
+
return "Bot mode joke";
|
|
245
|
+
}
|
|
246
|
+
this.promptKinds.push("user");
|
|
247
|
+
return `OpenClaw bridge: ${params.message}`;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
160
251
|
class ThinkingTraceBridge {
|
|
161
252
|
readonly supportsThinkingTrace = true;
|
|
162
253
|
readonly conversationMessages: string[] = [];
|
|
@@ -2155,6 +2246,341 @@ test("group sessions can mute and unmute bot replies without stopping participan
|
|
|
2155
2246
|
await Promise.all([waitForClose(appOne), waitForClose(appTwo)]);
|
|
2156
2247
|
});
|
|
2157
2248
|
|
|
2249
|
+
test("group bot mode stays quiet when disabled", async (t) => {
|
|
2250
|
+
const bridge = new BotModeBridge();
|
|
2251
|
+
const { invite } = await createGroupBotModeHarness(t, bridge, {
|
|
2252
|
+
botMode: false,
|
|
2253
|
+
botModeSilentJoinDelayMs: 30,
|
|
2254
|
+
botModeIdleDelayMs: 30,
|
|
2255
|
+
});
|
|
2256
|
+
const app = await connectGroupApp({
|
|
2257
|
+
invite,
|
|
2258
|
+
appId: "app-one",
|
|
2259
|
+
displayName: "SolarFox",
|
|
2260
|
+
});
|
|
2261
|
+
t.after(async () => {
|
|
2262
|
+
app.close();
|
|
2263
|
+
await waitForClose(app);
|
|
2264
|
+
});
|
|
2265
|
+
|
|
2266
|
+
await waitForNoMessage(app, 120);
|
|
2267
|
+
assert.deepEqual(bridge.promptKinds, []);
|
|
2268
|
+
});
|
|
2269
|
+
|
|
2270
|
+
test("group bot mode greets a silent participant after the configured join delay", async (t) => {
|
|
2271
|
+
const bridge = new BotModeBridge();
|
|
2272
|
+
const { invite } = await createGroupBotModeHarness(t, bridge, {
|
|
2273
|
+
botMode: true,
|
|
2274
|
+
botModeSilentJoinDelayMs: 40,
|
|
2275
|
+
botModeIdleDelayMs: 250,
|
|
2276
|
+
});
|
|
2277
|
+
const app = await connectGroupApp({
|
|
2278
|
+
invite,
|
|
2279
|
+
appId: "app-one",
|
|
2280
|
+
displayName: "SolarFox",
|
|
2281
|
+
});
|
|
2282
|
+
t.after(async () => {
|
|
2283
|
+
app.close();
|
|
2284
|
+
await waitForClose(app);
|
|
2285
|
+
});
|
|
2286
|
+
|
|
2287
|
+
const proactive = await nextRelayPayload(app, invite);
|
|
2288
|
+
assert.equal(proactive.kind, "assistant_message");
|
|
2289
|
+
assert.equal(proactive.text, "Bot mode hello");
|
|
2290
|
+
assert.deepEqual(bridge.promptKinds, ["silent_join"]);
|
|
2291
|
+
assert.match(bridge.prompts[0]!, /SolarFox/u);
|
|
2292
|
+
assert.match(bridge.prompts[0]!, /has not sent any message yet/u);
|
|
2293
|
+
assert.doesNotMatch(
|
|
2294
|
+
bridge.prompts[0]!,
|
|
2295
|
+
/write the proactive message in English/u,
|
|
2296
|
+
);
|
|
2297
|
+
await waitForNoMessage(app, 120);
|
|
2298
|
+
});
|
|
2299
|
+
|
|
2300
|
+
test("group bot mode cancels the silent-join greeting after the participant speaks", async (t) => {
|
|
2301
|
+
const bridge = new BotModeBridge();
|
|
2302
|
+
const { invite } = await createGroupBotModeHarness(t, bridge, {
|
|
2303
|
+
botMode: true,
|
|
2304
|
+
botModeSilentJoinDelayMs: 80,
|
|
2305
|
+
botModeIdleDelayMs: 250,
|
|
2306
|
+
});
|
|
2307
|
+
const app = await connectGroupApp({
|
|
2308
|
+
invite,
|
|
2309
|
+
appId: "app-one",
|
|
2310
|
+
displayName: "SolarFox",
|
|
2311
|
+
});
|
|
2312
|
+
t.after(async () => {
|
|
2313
|
+
app.close();
|
|
2314
|
+
await waitForClose(app);
|
|
2315
|
+
});
|
|
2316
|
+
|
|
2317
|
+
const replyFramesPromise = nextMessages(app, 2);
|
|
2318
|
+
app.send(
|
|
2319
|
+
JSON.stringify({
|
|
2320
|
+
type: "app:frame",
|
|
2321
|
+
envelope: encryptPayload({
|
|
2322
|
+
sessionId: invite.sessionId,
|
|
2323
|
+
sessionKey: invite.sessionKey,
|
|
2324
|
+
payload: {
|
|
2325
|
+
kind: "user_message",
|
|
2326
|
+
appId: "app-one",
|
|
2327
|
+
text: "hello there",
|
|
2328
|
+
clientMessageId: "bot-mode-user-1",
|
|
2329
|
+
sentAt: new Date().toISOString(),
|
|
2330
|
+
},
|
|
2331
|
+
}),
|
|
2332
|
+
}),
|
|
2333
|
+
);
|
|
2334
|
+
|
|
2335
|
+
const replyFrames = await replyFramesPromise;
|
|
2336
|
+
const participantEcho = decryptRelayPayload(replyFrames[0]!, invite);
|
|
2337
|
+
const assistantReply = decryptRelayPayload(replyFrames[1]!, invite);
|
|
2338
|
+
assert.equal(participantEcho.kind, "participant_message");
|
|
2339
|
+
assert.equal(assistantReply.kind, "assistant_message");
|
|
2340
|
+
assert.deepEqual(bridge.promptKinds, ["user"]);
|
|
2341
|
+
await waitForNoMessage(app, 140);
|
|
2342
|
+
});
|
|
2343
|
+
|
|
2344
|
+
test("group bot mode sends an idle follow-up after the room stays quiet", async (t) => {
|
|
2345
|
+
const bridge = new BotModeBridge();
|
|
2346
|
+
const { invite } = await createGroupBotModeHarness(t, bridge, {
|
|
2347
|
+
botMode: true,
|
|
2348
|
+
botModeSilentJoinDelayMs: 250,
|
|
2349
|
+
botModeIdleDelayMs: 60,
|
|
2350
|
+
});
|
|
2351
|
+
const app = await connectGroupApp({
|
|
2352
|
+
invite,
|
|
2353
|
+
appId: "app-one",
|
|
2354
|
+
displayName: "SolarFox",
|
|
2355
|
+
});
|
|
2356
|
+
t.after(async () => {
|
|
2357
|
+
app.close();
|
|
2358
|
+
await waitForClose(app);
|
|
2359
|
+
});
|
|
2360
|
+
|
|
2361
|
+
const replyFramesPromise = nextMessages(app, 2);
|
|
2362
|
+
app.send(
|
|
2363
|
+
JSON.stringify({
|
|
2364
|
+
type: "app:frame",
|
|
2365
|
+
envelope: encryptPayload({
|
|
2366
|
+
sessionId: invite.sessionId,
|
|
2367
|
+
sessionKey: invite.sessionKey,
|
|
2368
|
+
payload: {
|
|
2369
|
+
kind: "user_message",
|
|
2370
|
+
appId: "app-one",
|
|
2371
|
+
text: "keep this in mind",
|
|
2372
|
+
clientMessageId: "bot-mode-user-2",
|
|
2373
|
+
sentAt: new Date().toISOString(),
|
|
2374
|
+
},
|
|
2375
|
+
}),
|
|
2376
|
+
}),
|
|
2377
|
+
);
|
|
2378
|
+
const replyFrames = await replyFramesPromise;
|
|
2379
|
+
assert.equal(decryptRelayPayload(replyFrames[0]!, invite).kind, "participant_message");
|
|
2380
|
+
assert.equal(decryptRelayPayload(replyFrames[1]!, invite).kind, "assistant_message");
|
|
2381
|
+
|
|
2382
|
+
const idleFollowUp = await nextRelayPayload(app, invite);
|
|
2383
|
+
assert.equal(idleFollowUp.kind, "assistant_message");
|
|
2384
|
+
assert.equal(idleFollowUp.text, "Bot mode joke");
|
|
2385
|
+
assert.deepEqual(bridge.promptKinds, ["user", "idle_group"]);
|
|
2386
|
+
assert.match(bridge.prompts[1]!, /has had no new message/u);
|
|
2387
|
+
assert.match(
|
|
2388
|
+
bridge.prompts[1]!,
|
|
2389
|
+
/Write the proactive message in the same language as the recent user\/assistant conversation already in this session\./u,
|
|
2390
|
+
);
|
|
2391
|
+
});
|
|
2392
|
+
|
|
2393
|
+
test("group bot mode idle timing ignores non-human assistant broadcasts", async (t) => {
|
|
2394
|
+
const bridge = new BotModeBridge();
|
|
2395
|
+
const { invite, provider } = await createGroupBotModeHarness(t, bridge, {
|
|
2396
|
+
botMode: true,
|
|
2397
|
+
botModeSilentJoinDelayMs: 250,
|
|
2398
|
+
botModeIdleDelayMs: 160,
|
|
2399
|
+
});
|
|
2400
|
+
const app = await connectGroupApp({
|
|
2401
|
+
invite,
|
|
2402
|
+
appId: "app-one",
|
|
2403
|
+
displayName: "SolarFox",
|
|
2404
|
+
});
|
|
2405
|
+
t.after(async () => {
|
|
2406
|
+
app.close();
|
|
2407
|
+
await waitForClose(app);
|
|
2408
|
+
});
|
|
2409
|
+
|
|
2410
|
+
const replyFramesPromise = nextMessages(app, 2);
|
|
2411
|
+
app.send(
|
|
2412
|
+
JSON.stringify({
|
|
2413
|
+
type: "app:frame",
|
|
2414
|
+
envelope: encryptPayload({
|
|
2415
|
+
sessionId: invite.sessionId,
|
|
2416
|
+
sessionKey: invite.sessionKey,
|
|
2417
|
+
payload: {
|
|
2418
|
+
kind: "user_message",
|
|
2419
|
+
appId: "app-one",
|
|
2420
|
+
text: "keep the room warm",
|
|
2421
|
+
clientMessageId: "bot-mode-user-3",
|
|
2422
|
+
sentAt: new Date().toISOString(),
|
|
2423
|
+
},
|
|
2424
|
+
}),
|
|
2425
|
+
}),
|
|
2426
|
+
);
|
|
2427
|
+
await replyFramesPromise;
|
|
2428
|
+
|
|
2429
|
+
await new Promise((resolve) => setTimeout(resolve, 110));
|
|
2430
|
+
const qrPayloadPromise = nextRelayPayload(app, invite);
|
|
2431
|
+
await provider.getSessionQrBundle(invite.sessionId, { notifyParticipants: true });
|
|
2432
|
+
const qrPayload = await qrPayloadPromise;
|
|
2433
|
+
assert.equal(qrPayload.kind, "assistant_message");
|
|
2434
|
+
|
|
2435
|
+
const idleWaitStartedAt = Date.now();
|
|
2436
|
+
const idleFollowUp = await nextRelayPayload(app, invite);
|
|
2437
|
+
const idleElapsedMs = Date.now() - idleWaitStartedAt;
|
|
2438
|
+
assert.equal(idleFollowUp.kind, "assistant_message");
|
|
2439
|
+
assert.equal(idleFollowUp.text, "Bot mode joke");
|
|
2440
|
+
assert.ok(
|
|
2441
|
+
idleElapsedMs < 120,
|
|
2442
|
+
`expected idle follow-up without assistant reset, waited ${idleElapsedMs}ms`,
|
|
2443
|
+
);
|
|
2444
|
+
});
|
|
2445
|
+
|
|
2446
|
+
test("group bot mode idle timing ignores participant joins", async (t) => {
|
|
2447
|
+
const bridge = new BotModeBridge();
|
|
2448
|
+
const { invite } = await createGroupBotModeHarness(t, bridge, {
|
|
2449
|
+
botMode: true,
|
|
2450
|
+
botModeSilentJoinDelayMs: 250,
|
|
2451
|
+
botModeIdleDelayMs: 160,
|
|
2452
|
+
});
|
|
2453
|
+
const appOne = await connectGroupApp({
|
|
2454
|
+
invite,
|
|
2455
|
+
appId: "app-one",
|
|
2456
|
+
displayName: "SolarFox",
|
|
2457
|
+
});
|
|
2458
|
+
let appTwo: WebSocket | undefined;
|
|
2459
|
+
t.after(async () => {
|
|
2460
|
+
appOne.close();
|
|
2461
|
+
if (appTwo) {
|
|
2462
|
+
appTwo.close();
|
|
2463
|
+
}
|
|
2464
|
+
await Promise.all([
|
|
2465
|
+
waitForClose(appOne),
|
|
2466
|
+
...(appTwo ? [waitForClose(appTwo)] : []),
|
|
2467
|
+
]);
|
|
2468
|
+
});
|
|
2469
|
+
|
|
2470
|
+
const replyFramesPromise = nextMessages(appOne, 2);
|
|
2471
|
+
appOne.send(
|
|
2472
|
+
JSON.stringify({
|
|
2473
|
+
type: "app:frame",
|
|
2474
|
+
envelope: encryptPayload({
|
|
2475
|
+
sessionId: invite.sessionId,
|
|
2476
|
+
sessionKey: invite.sessionKey,
|
|
2477
|
+
payload: {
|
|
2478
|
+
kind: "user_message",
|
|
2479
|
+
appId: "app-one",
|
|
2480
|
+
text: "staying active",
|
|
2481
|
+
clientMessageId: "bot-mode-user-4",
|
|
2482
|
+
sentAt: new Date().toISOString(),
|
|
2483
|
+
},
|
|
2484
|
+
}),
|
|
2485
|
+
}),
|
|
2486
|
+
);
|
|
2487
|
+
await replyFramesPromise;
|
|
2488
|
+
|
|
2489
|
+
await new Promise((resolve) => setTimeout(resolve, 110));
|
|
2490
|
+
const joinFramesPromise = nextMessages(appOne, 2);
|
|
2491
|
+
appTwo = await connectGroupApp({
|
|
2492
|
+
invite,
|
|
2493
|
+
appId: "app-two",
|
|
2494
|
+
displayName: "RiverCat",
|
|
2495
|
+
expectedFrameCount: 5,
|
|
2496
|
+
});
|
|
2497
|
+
await joinFramesPromise;
|
|
2498
|
+
|
|
2499
|
+
const idleWaitStartedAt = Date.now();
|
|
2500
|
+
const idleFollowUp = await nextRelayPayload(appOne, invite);
|
|
2501
|
+
const idleElapsedMs = Date.now() - idleWaitStartedAt;
|
|
2502
|
+
assert.equal(idleFollowUp.kind, "assistant_message");
|
|
2503
|
+
assert.equal(idleFollowUp.text, "Bot mode joke");
|
|
2504
|
+
assert.ok(
|
|
2505
|
+
idleElapsedMs < 120,
|
|
2506
|
+
`expected idle follow-up without join reset, waited ${idleElapsedMs}ms`,
|
|
2507
|
+
);
|
|
2508
|
+
});
|
|
2509
|
+
|
|
2510
|
+
test("group bot mode respects /mute-bot and suppresses proactive replies", async (t) => {
|
|
2511
|
+
const bridge = new BotModeBridge();
|
|
2512
|
+
const { invite } = await createGroupBotModeHarness(t, bridge, {
|
|
2513
|
+
botMode: true,
|
|
2514
|
+
botModeSilentJoinDelayMs: 50,
|
|
2515
|
+
botModeIdleDelayMs: 70,
|
|
2516
|
+
});
|
|
2517
|
+
const app = await connectGroupApp({
|
|
2518
|
+
invite,
|
|
2519
|
+
appId: "app-one",
|
|
2520
|
+
displayName: "SolarFox",
|
|
2521
|
+
});
|
|
2522
|
+
t.after(async () => {
|
|
2523
|
+
app.close();
|
|
2524
|
+
await waitForClose(app);
|
|
2525
|
+
});
|
|
2526
|
+
|
|
2527
|
+
const muteFramesPromise = nextMessages(app, 2);
|
|
2528
|
+
app.send(
|
|
2529
|
+
JSON.stringify({
|
|
2530
|
+
type: "app:frame",
|
|
2531
|
+
envelope: encryptPayload({
|
|
2532
|
+
sessionId: invite.sessionId,
|
|
2533
|
+
sessionKey: invite.sessionKey,
|
|
2534
|
+
payload: {
|
|
2535
|
+
kind: "user_message",
|
|
2536
|
+
appId: "app-one",
|
|
2537
|
+
text: "/mute-bot",
|
|
2538
|
+
clientMessageId: "bot-mode-mute-1",
|
|
2539
|
+
sentAt: new Date().toISOString(),
|
|
2540
|
+
},
|
|
2541
|
+
}),
|
|
2542
|
+
}),
|
|
2543
|
+
);
|
|
2544
|
+
await muteFramesPromise;
|
|
2545
|
+
|
|
2546
|
+
await waitForNoMessage(app, 150);
|
|
2547
|
+
assert.deepEqual(bridge.promptKinds, []);
|
|
2548
|
+
});
|
|
2549
|
+
|
|
2550
|
+
test("group bot mode does not greet the same silent participant twice after reconnect", async (t) => {
|
|
2551
|
+
const bridge = new BotModeBridge();
|
|
2552
|
+
const { invite } = await createGroupBotModeHarness(t, bridge, {
|
|
2553
|
+
botMode: true,
|
|
2554
|
+
botModeSilentJoinDelayMs: 40,
|
|
2555
|
+
botModeIdleDelayMs: 250,
|
|
2556
|
+
});
|
|
2557
|
+
const app = await connectGroupApp({
|
|
2558
|
+
invite,
|
|
2559
|
+
appId: "app-one",
|
|
2560
|
+
displayName: "SolarFox",
|
|
2561
|
+
});
|
|
2562
|
+
|
|
2563
|
+
const proactive = await nextRelayPayload(app, invite);
|
|
2564
|
+
assert.equal(proactive.kind, "assistant_message");
|
|
2565
|
+
assert.equal(proactive.text, "Bot mode hello");
|
|
2566
|
+
app.close();
|
|
2567
|
+
await waitForClose(app);
|
|
2568
|
+
|
|
2569
|
+
const reconnect = await connectGroupApp({
|
|
2570
|
+
invite,
|
|
2571
|
+
appId: "app-one",
|
|
2572
|
+
displayName: "SolarFox",
|
|
2573
|
+
expectedFrameCount: 4,
|
|
2574
|
+
});
|
|
2575
|
+
t.after(async () => {
|
|
2576
|
+
reconnect.close();
|
|
2577
|
+
await waitForClose(reconnect);
|
|
2578
|
+
});
|
|
2579
|
+
|
|
2580
|
+
await waitForNoMessage(reconnect, 120);
|
|
2581
|
+
assert.deepEqual(bridge.promptKinds, ["silent_join"]);
|
|
2582
|
+
});
|
|
2583
|
+
|
|
2158
2584
|
test("provider forwards unknown slash commands verbatim to the bridge even when bot replies are muted", async (t) => {
|
|
2159
2585
|
const relay = createRelayServer({
|
|
2160
2586
|
host: "127.0.0.1",
|