@privateclaw/privateclaw 0.1.17 → 0.1.23
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 +11 -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 +7 -2
- package/dist/bridges/openclaw-agent-bridge.js +554 -68
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/provider.d.ts +12 -1
- package/dist/provider.js +159 -6
- package/dist/provider.js.map +1 -1
- package/dist/types.d.ts +13 -2
- package/package.json +2 -2
- package/src/bridges/openai-compatible-bridge.ts +1 -0
- package/src/bridges/openclaw-agent-bridge.test.ts +572 -0
- package/src/bridges/openclaw-agent-bridge.ts +709 -75
- package/src/provider.test.ts +375 -0
- package/src/provider.ts +203 -8
- package/src/types.ts +17 -1
package/src/provider.test.ts
CHANGED
|
@@ -138,6 +138,83 @@ class GroupBridge {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
class HistoryRecordingBridge {
|
|
142
|
+
readonly conversationMessages: string[] = [];
|
|
143
|
+
readonly histories: Array<Array<{ role: string; text: string }>> = [];
|
|
144
|
+
|
|
145
|
+
async handleUserMessage(params: {
|
|
146
|
+
message: string;
|
|
147
|
+
history: ReadonlyArray<{ role: string; text: string }>;
|
|
148
|
+
}): Promise<string> {
|
|
149
|
+
this.conversationMessages.push(params.message);
|
|
150
|
+
this.histories.push(
|
|
151
|
+
params.history.map((turn) => ({
|
|
152
|
+
role: turn.role,
|
|
153
|
+
text: turn.text,
|
|
154
|
+
})),
|
|
155
|
+
);
|
|
156
|
+
return `OpenClaw bridge: ${params.message}`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
class ThinkingTraceBridge {
|
|
161
|
+
readonly supportsThinkingTrace = true;
|
|
162
|
+
readonly conversationMessages: string[] = [];
|
|
163
|
+
|
|
164
|
+
async handleUserMessage(params: {
|
|
165
|
+
message: string;
|
|
166
|
+
onThinkingTrace?: (snapshot: {
|
|
167
|
+
entries: ReadonlyArray<{
|
|
168
|
+
id: string;
|
|
169
|
+
kind: "thought" | "action" | "result" | "error";
|
|
170
|
+
title: string;
|
|
171
|
+
text: string;
|
|
172
|
+
sentAt: string;
|
|
173
|
+
toolName?: string;
|
|
174
|
+
}>;
|
|
175
|
+
sentAt: string;
|
|
176
|
+
summary: string;
|
|
177
|
+
}) => void | Promise<void>;
|
|
178
|
+
}): Promise<string> {
|
|
179
|
+
this.conversationMessages.push(params.message);
|
|
180
|
+
await params.onThinkingTrace?.({
|
|
181
|
+
sentAt: "2026-01-01T00:00:00.000Z",
|
|
182
|
+
summary: "Planning the reply",
|
|
183
|
+
entries: [
|
|
184
|
+
{
|
|
185
|
+
id: "thinking-entry-1",
|
|
186
|
+
kind: "thought",
|
|
187
|
+
title: "Thinking",
|
|
188
|
+
text: "Planning the reply",
|
|
189
|
+
sentAt: "2026-01-01T00:00:00.000Z",
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
});
|
|
193
|
+
await params.onThinkingTrace?.({
|
|
194
|
+
sentAt: "2026-01-01T00:00:01.000Z",
|
|
195
|
+
summary: "read: Opened README excerpt",
|
|
196
|
+
entries: [
|
|
197
|
+
{
|
|
198
|
+
id: "thinking-entry-1",
|
|
199
|
+
kind: "thought",
|
|
200
|
+
title: "Thinking",
|
|
201
|
+
text: "Planning the reply",
|
|
202
|
+
sentAt: "2026-01-01T00:00:00.000Z",
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: "thinking-entry-2",
|
|
206
|
+
kind: "action",
|
|
207
|
+
title: "Tool • read",
|
|
208
|
+
text: "Opened README excerpt",
|
|
209
|
+
sentAt: "2026-01-01T00:00:01.000Z",
|
|
210
|
+
toolName: "read",
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
return "Bridge final answer";
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
141
218
|
class VoiceTranscribingBridge {
|
|
142
219
|
readonly conversationMessages: string[] = [];
|
|
143
220
|
readonly transcriptionRequests: Array<{ sessionId: string; requestId: string }> = [];
|
|
@@ -1249,6 +1326,7 @@ test("provider group sessions broadcast participant messages and assign unique l
|
|
|
1249
1326
|
appId: "app-one",
|
|
1250
1327
|
appVersion: "flutter-test",
|
|
1251
1328
|
deviceLabel: "Tester One",
|
|
1329
|
+
supportsThinkingTrace: true,
|
|
1252
1330
|
sentAt: new Date().toISOString(),
|
|
1253
1331
|
},
|
|
1254
1332
|
}),
|
|
@@ -1282,6 +1360,7 @@ test("provider group sessions broadcast participant messages and assign unique l
|
|
|
1282
1360
|
appId: "app-two",
|
|
1283
1361
|
appVersion: "flutter-test",
|
|
1284
1362
|
deviceLabel: "Tester Two",
|
|
1363
|
+
supportsThinkingTrace: true,
|
|
1285
1364
|
sentAt: new Date().toISOString(),
|
|
1286
1365
|
},
|
|
1287
1366
|
}),
|
|
@@ -1356,6 +1435,166 @@ test("provider group sessions broadcast participant messages and assign unique l
|
|
|
1356
1435
|
await Promise.all([waitForClose(appOne), waitForClose(appTwo)]);
|
|
1357
1436
|
});
|
|
1358
1437
|
|
|
1438
|
+
test("provider group sessions broadcast thinking traces before the final assistant reply", async (t) => {
|
|
1439
|
+
const relay = createRelayServer({
|
|
1440
|
+
host: "127.0.0.1",
|
|
1441
|
+
port: 0,
|
|
1442
|
+
sessionTtlMs: 60_000,
|
|
1443
|
+
frameCacheSize: 8,
|
|
1444
|
+
});
|
|
1445
|
+
const { port } = await relay.start();
|
|
1446
|
+
t.after(async () => {
|
|
1447
|
+
await relay.stop();
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
const bridge = new ThinkingTraceBridge();
|
|
1451
|
+
const provider = new PrivateClawProvider({
|
|
1452
|
+
providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
|
|
1453
|
+
appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
|
|
1454
|
+
bridge,
|
|
1455
|
+
defaultTtlMs: DEFAULT_SESSION_TTL_MS,
|
|
1456
|
+
});
|
|
1457
|
+
await provider.connect();
|
|
1458
|
+
t.after(async () => {
|
|
1459
|
+
await provider.dispose();
|
|
1460
|
+
});
|
|
1461
|
+
|
|
1462
|
+
const inviteBundle = await provider.createInviteBundle({ groupMode: true });
|
|
1463
|
+
const invite = decodeInviteString(inviteBundle.inviteUri);
|
|
1464
|
+
|
|
1465
|
+
const appOneUrl = new URL(invite.appWsUrl);
|
|
1466
|
+
appOneUrl.searchParams.set("appId", "app-one");
|
|
1467
|
+
const appOne = new WebSocket(appOneUrl.toString());
|
|
1468
|
+
const appOneAttached = nextMessage(appOne);
|
|
1469
|
+
await waitForOpen(appOne);
|
|
1470
|
+
assert.equal((await appOneAttached).type, "relay:attached");
|
|
1471
|
+
const appOneInitialFramesPromise = nextMessages(appOne, 3);
|
|
1472
|
+
appOne.send(
|
|
1473
|
+
JSON.stringify({
|
|
1474
|
+
type: "app:frame",
|
|
1475
|
+
envelope: encryptPayload({
|
|
1476
|
+
sessionId: invite.sessionId,
|
|
1477
|
+
sessionKey: invite.sessionKey,
|
|
1478
|
+
payload: {
|
|
1479
|
+
kind: "client_hello",
|
|
1480
|
+
appId: "app-one",
|
|
1481
|
+
appVersion: "flutter-test",
|
|
1482
|
+
deviceLabel: "Tester One",
|
|
1483
|
+
supportsThinkingTrace: true,
|
|
1484
|
+
sentAt: new Date().toISOString(),
|
|
1485
|
+
},
|
|
1486
|
+
}),
|
|
1487
|
+
}),
|
|
1488
|
+
);
|
|
1489
|
+
const appOneInitialFrames = await appOneInitialFramesPromise;
|
|
1490
|
+
const appOneCapabilities = decryptRelayPayload(appOneInitialFrames[1]!, invite);
|
|
1491
|
+
assert.equal(appOneCapabilities.kind, "provider_capabilities");
|
|
1492
|
+
|
|
1493
|
+
const appTwoUrl = new URL(invite.appWsUrl);
|
|
1494
|
+
appTwoUrl.searchParams.set("appId", "app-two");
|
|
1495
|
+
const appTwo = new WebSocket(appTwoUrl.toString());
|
|
1496
|
+
const appTwoAttached = nextMessage(appTwo);
|
|
1497
|
+
await waitForOpen(appTwo);
|
|
1498
|
+
assert.equal((await appTwoAttached).type, "relay:attached");
|
|
1499
|
+
const appTwoInitialFramesPromise = nextMessages(appTwo, 3);
|
|
1500
|
+
const appOneJoinFramesPromise = nextMessages(appOne, 2);
|
|
1501
|
+
appTwo.send(
|
|
1502
|
+
JSON.stringify({
|
|
1503
|
+
type: "app:frame",
|
|
1504
|
+
envelope: encryptPayload({
|
|
1505
|
+
sessionId: invite.sessionId,
|
|
1506
|
+
sessionKey: invite.sessionKey,
|
|
1507
|
+
payload: {
|
|
1508
|
+
kind: "client_hello",
|
|
1509
|
+
appId: "app-two",
|
|
1510
|
+
appVersion: "flutter-test",
|
|
1511
|
+
deviceLabel: "Tester Two",
|
|
1512
|
+
supportsThinkingTrace: true,
|
|
1513
|
+
sentAt: new Date().toISOString(),
|
|
1514
|
+
},
|
|
1515
|
+
}),
|
|
1516
|
+
}),
|
|
1517
|
+
);
|
|
1518
|
+
await Promise.all([appTwoInitialFramesPromise, appOneJoinFramesPromise]);
|
|
1519
|
+
|
|
1520
|
+
const appOneReplyFramesPromise = nextMessages(appOne, 6);
|
|
1521
|
+
const appTwoReplyFramesPromise = nextMessages(appTwo, 6);
|
|
1522
|
+
appOne.send(
|
|
1523
|
+
JSON.stringify({
|
|
1524
|
+
type: "app:frame",
|
|
1525
|
+
envelope: encryptPayload({
|
|
1526
|
+
sessionId: invite.sessionId,
|
|
1527
|
+
sessionKey: invite.sessionKey,
|
|
1528
|
+
payload: {
|
|
1529
|
+
kind: "user_message",
|
|
1530
|
+
appId: "app-one",
|
|
1531
|
+
text: "show the README summary",
|
|
1532
|
+
clientMessageId: "trace-message-1",
|
|
1533
|
+
sentAt: new Date().toISOString(),
|
|
1534
|
+
},
|
|
1535
|
+
}),
|
|
1536
|
+
}),
|
|
1537
|
+
);
|
|
1538
|
+
|
|
1539
|
+
const [appOneFrames, appTwoFrames] = await Promise.all([
|
|
1540
|
+
appOneReplyFramesPromise,
|
|
1541
|
+
appTwoReplyFramesPromise,
|
|
1542
|
+
]);
|
|
1543
|
+
const appOnePayloads = appOneFrames.map((frame) => decryptRelayPayload(frame, invite));
|
|
1544
|
+
const appTwoPayloads = appTwoFrames.map((frame) => decryptRelayPayload(frame, invite));
|
|
1545
|
+
|
|
1546
|
+
assert.deepEqual(
|
|
1547
|
+
appOnePayloads.map((payload) => payload.kind),
|
|
1548
|
+
[
|
|
1549
|
+
"participant_message",
|
|
1550
|
+
"thinking_message",
|
|
1551
|
+
"thinking_message",
|
|
1552
|
+
"thinking_message",
|
|
1553
|
+
"thinking_message",
|
|
1554
|
+
"assistant_message",
|
|
1555
|
+
],
|
|
1556
|
+
);
|
|
1557
|
+
assert.deepEqual(
|
|
1558
|
+
appTwoPayloads.map((payload) => payload.kind),
|
|
1559
|
+
[
|
|
1560
|
+
"participant_message",
|
|
1561
|
+
"thinking_message",
|
|
1562
|
+
"thinking_message",
|
|
1563
|
+
"thinking_message",
|
|
1564
|
+
"thinking_message",
|
|
1565
|
+
"assistant_message",
|
|
1566
|
+
],
|
|
1567
|
+
);
|
|
1568
|
+
|
|
1569
|
+
const appTwoThinkingPayloads = appTwoPayloads.filter(
|
|
1570
|
+
(
|
|
1571
|
+
payload,
|
|
1572
|
+
): payload is Extract<PrivateClawPayload, { kind: "thinking_message" }> =>
|
|
1573
|
+
payload.kind === "thinking_message",
|
|
1574
|
+
);
|
|
1575
|
+
assert.equal(appTwoThinkingPayloads.length, 4);
|
|
1576
|
+
assert.equal(appTwoThinkingPayloads[0]?.status, "started");
|
|
1577
|
+
assert.equal(appTwoThinkingPayloads[0]?.entries.length, 0);
|
|
1578
|
+
assert.equal(appTwoThinkingPayloads[1]?.status, "streaming");
|
|
1579
|
+
assert.equal(appTwoThinkingPayloads[1]?.entries.length, 1);
|
|
1580
|
+
assert.equal(appTwoThinkingPayloads[2]?.status, "streaming");
|
|
1581
|
+
assert.equal(appTwoThinkingPayloads[2]?.entries.length, 2);
|
|
1582
|
+
assert.equal(appTwoThinkingPayloads[2]?.entries[1]?.toolName, "read");
|
|
1583
|
+
assert.equal(appTwoThinkingPayloads[3]?.status, "completed");
|
|
1584
|
+
assert.equal(appTwoThinkingPayloads[3]?.summary, "read: Opened README excerpt");
|
|
1585
|
+
|
|
1586
|
+
const finalAssistant = appTwoPayloads[5];
|
|
1587
|
+
assert.equal(finalAssistant?.kind, "assistant_message");
|
|
1588
|
+
if (finalAssistant?.kind === "assistant_message") {
|
|
1589
|
+
assert.equal(finalAssistant.text, "Bridge final answer");
|
|
1590
|
+
assert.equal(finalAssistant.replyTo, "trace-message-1");
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
appOne.close();
|
|
1594
|
+
appTwo.close();
|
|
1595
|
+
await Promise.all([waitForClose(appOne), waitForClose(appTwo)]);
|
|
1596
|
+
});
|
|
1597
|
+
|
|
1359
1598
|
test("provider group sessions broadcast raw voice first and only reply with the final assistant answer", async (t) => {
|
|
1360
1599
|
const relay = createRelayServer({
|
|
1361
1600
|
host: "127.0.0.1",
|
|
@@ -1916,6 +2155,142 @@ test("group sessions can mute and unmute bot replies without stopping participan
|
|
|
1916
2155
|
await Promise.all([waitForClose(appOne), waitForClose(appTwo)]);
|
|
1917
2156
|
});
|
|
1918
2157
|
|
|
2158
|
+
test("provider forwards unknown slash commands verbatim to the bridge even when bot replies are muted", async (t) => {
|
|
2159
|
+
const relay = createRelayServer({
|
|
2160
|
+
host: "127.0.0.1",
|
|
2161
|
+
port: 0,
|
|
2162
|
+
sessionTtlMs: 60_000,
|
|
2163
|
+
frameCacheSize: 8,
|
|
2164
|
+
});
|
|
2165
|
+
const { port } = await relay.start();
|
|
2166
|
+
t.after(async () => {
|
|
2167
|
+
await relay.stop();
|
|
2168
|
+
});
|
|
2169
|
+
|
|
2170
|
+
const bridge = new HistoryRecordingBridge();
|
|
2171
|
+
const provider = new PrivateClawProvider({
|
|
2172
|
+
providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
|
|
2173
|
+
appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
|
|
2174
|
+
bridge,
|
|
2175
|
+
defaultTtlMs: DEFAULT_SESSION_TTL_MS,
|
|
2176
|
+
});
|
|
2177
|
+
await provider.connect();
|
|
2178
|
+
t.after(async () => {
|
|
2179
|
+
await provider.dispose();
|
|
2180
|
+
});
|
|
2181
|
+
|
|
2182
|
+
const inviteBundle = await provider.createInviteBundle({ groupMode: true });
|
|
2183
|
+
const invite = decodeInviteString(inviteBundle.inviteUri);
|
|
2184
|
+
|
|
2185
|
+
const appUrl = new URL(invite.appWsUrl);
|
|
2186
|
+
appUrl.searchParams.set("appId", "app-one");
|
|
2187
|
+
const appSocket = new WebSocket(appUrl.toString());
|
|
2188
|
+
const attached = nextMessage(appSocket);
|
|
2189
|
+
await waitForOpen(appSocket);
|
|
2190
|
+
assert.equal((await attached).type, "relay:attached");
|
|
2191
|
+
const initialFrames = nextMessages(appSocket, 3);
|
|
2192
|
+
appSocket.send(
|
|
2193
|
+
JSON.stringify({
|
|
2194
|
+
type: "app:frame",
|
|
2195
|
+
envelope: encryptPayload({
|
|
2196
|
+
sessionId: invite.sessionId,
|
|
2197
|
+
sessionKey: invite.sessionKey,
|
|
2198
|
+
payload: {
|
|
2199
|
+
kind: "client_hello",
|
|
2200
|
+
appId: "app-one",
|
|
2201
|
+
displayName: "SolarFox",
|
|
2202
|
+
appVersion: "flutter-test",
|
|
2203
|
+
deviceLabel: "Tester One",
|
|
2204
|
+
sentAt: new Date().toISOString(),
|
|
2205
|
+
},
|
|
2206
|
+
}),
|
|
2207
|
+
}),
|
|
2208
|
+
);
|
|
2209
|
+
await initialFrames;
|
|
2210
|
+
|
|
2211
|
+
const muteFramesPromise = nextMessages(appSocket, 2);
|
|
2212
|
+
appSocket.send(
|
|
2213
|
+
JSON.stringify({
|
|
2214
|
+
type: "app:frame",
|
|
2215
|
+
envelope: encryptPayload({
|
|
2216
|
+
sessionId: invite.sessionId,
|
|
2217
|
+
sessionKey: invite.sessionKey,
|
|
2218
|
+
payload: {
|
|
2219
|
+
kind: "user_message",
|
|
2220
|
+
appId: "app-one",
|
|
2221
|
+
text: "/mute-bot",
|
|
2222
|
+
clientMessageId: "mute-bot-slash",
|
|
2223
|
+
sentAt: new Date().toISOString(),
|
|
2224
|
+
},
|
|
2225
|
+
}),
|
|
2226
|
+
}),
|
|
2227
|
+
);
|
|
2228
|
+
await muteFramesPromise;
|
|
2229
|
+
|
|
2230
|
+
const firstSlashFramesPromise = nextMessages(appSocket, 2);
|
|
2231
|
+
appSocket.send(
|
|
2232
|
+
JSON.stringify({
|
|
2233
|
+
type: "app:frame",
|
|
2234
|
+
envelope: encryptPayload({
|
|
2235
|
+
sessionId: invite.sessionId,
|
|
2236
|
+
sessionKey: invite.sessionKey,
|
|
2237
|
+
payload: {
|
|
2238
|
+
kind: "user_message",
|
|
2239
|
+
appId: "app-one",
|
|
2240
|
+
text: "/help tools",
|
|
2241
|
+
clientMessageId: "slash-help-1",
|
|
2242
|
+
sentAt: new Date().toISOString(),
|
|
2243
|
+
},
|
|
2244
|
+
}),
|
|
2245
|
+
}),
|
|
2246
|
+
);
|
|
2247
|
+
|
|
2248
|
+
const firstSlashFrames = await firstSlashFramesPromise;
|
|
2249
|
+
const firstParticipant = decryptRelayPayload(firstSlashFrames[0]!, invite);
|
|
2250
|
+
const firstAssistant = decryptRelayPayload(firstSlashFrames[1]!, invite);
|
|
2251
|
+
assert.equal(firstParticipant.kind, "participant_message");
|
|
2252
|
+
assert.equal(firstParticipant.text, "/help tools");
|
|
2253
|
+
assert.equal(firstAssistant.kind, "assistant_message");
|
|
2254
|
+
assert.equal(firstAssistant.text, "OpenClaw bridge: /help tools");
|
|
2255
|
+
assert.deepEqual(bridge.conversationMessages, ["/help tools"]);
|
|
2256
|
+
|
|
2257
|
+
const secondSlashFramesPromise = nextMessages(appSocket, 2);
|
|
2258
|
+
appSocket.send(
|
|
2259
|
+
JSON.stringify({
|
|
2260
|
+
type: "app:frame",
|
|
2261
|
+
envelope: encryptPayload({
|
|
2262
|
+
sessionId: invite.sessionId,
|
|
2263
|
+
sessionKey: invite.sessionKey,
|
|
2264
|
+
payload: {
|
|
2265
|
+
kind: "user_message",
|
|
2266
|
+
appId: "app-one",
|
|
2267
|
+
text: "/status",
|
|
2268
|
+
clientMessageId: "slash-status-1",
|
|
2269
|
+
sentAt: new Date().toISOString(),
|
|
2270
|
+
},
|
|
2271
|
+
}),
|
|
2272
|
+
}),
|
|
2273
|
+
);
|
|
2274
|
+
|
|
2275
|
+
const secondSlashFrames = await secondSlashFramesPromise;
|
|
2276
|
+
const secondParticipant = decryptRelayPayload(secondSlashFrames[0]!, invite);
|
|
2277
|
+
const secondAssistant = decryptRelayPayload(secondSlashFrames[1]!, invite);
|
|
2278
|
+
assert.equal(secondParticipant.kind, "participant_message");
|
|
2279
|
+
assert.equal(secondParticipant.text, "/status");
|
|
2280
|
+
assert.equal(secondAssistant.kind, "assistant_message");
|
|
2281
|
+
assert.equal(secondAssistant.text, "OpenClaw bridge: /status");
|
|
2282
|
+
assert.deepEqual(bridge.conversationMessages, ["/help tools", "/status"]);
|
|
2283
|
+
assert.ok(
|
|
2284
|
+
bridge.histories[1]?.some((turn) => turn.role === "user" && turn.text === "/help tools"),
|
|
2285
|
+
);
|
|
2286
|
+
assert.ok(
|
|
2287
|
+
bridge.histories[1]?.every((turn) => turn.text !== "SolarFox: /help tools"),
|
|
2288
|
+
);
|
|
2289
|
+
|
|
2290
|
+
appSocket.close();
|
|
2291
|
+
await waitForClose(appSocket);
|
|
2292
|
+
});
|
|
2293
|
+
|
|
1919
2294
|
test("group sessions keep running when one participant leaves and later rejoins", async (t) => {
|
|
1920
2295
|
const relay = createRelayServer({
|
|
1921
2296
|
host: "127.0.0.1",
|