@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
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 }> = [];
|
|
@@ -161,6 +238,36 @@ class VoiceTranscribingBridge {
|
|
|
161
238
|
}
|
|
162
239
|
}
|
|
163
240
|
|
|
241
|
+
class DirectAudioTranscriber {
|
|
242
|
+
readonly transcriptionRequests: Array<{ sessionId: string; requestId: string }> = [];
|
|
243
|
+
|
|
244
|
+
async transcribeAudioAttachments(params: {
|
|
245
|
+
sessionId: string;
|
|
246
|
+
requestId: string;
|
|
247
|
+
}): Promise<string> {
|
|
248
|
+
this.transcriptionRequests.push({
|
|
249
|
+
sessionId: params.sessionId,
|
|
250
|
+
requestId: params.requestId,
|
|
251
|
+
});
|
|
252
|
+
return "你好世界";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
class FailingAudioTranscriber {
|
|
257
|
+
readonly transcriptionRequests: Array<{ sessionId: string; requestId: string }> = [];
|
|
258
|
+
|
|
259
|
+
async transcribeAudioAttachments(params: {
|
|
260
|
+
sessionId: string;
|
|
261
|
+
requestId: string;
|
|
262
|
+
}): Promise<string> {
|
|
263
|
+
this.transcriptionRequests.push({
|
|
264
|
+
sessionId: params.sessionId,
|
|
265
|
+
requestId: params.requestId,
|
|
266
|
+
});
|
|
267
|
+
throw new Error("local STT failed");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
164
271
|
function buildVoiceAttachment() {
|
|
165
272
|
return {
|
|
166
273
|
id: "voice-attachment-1",
|
|
@@ -263,6 +370,91 @@ test("provider creates one-time invites and replies through the encrypted relay"
|
|
|
263
370
|
appSocket.terminate();
|
|
264
371
|
});
|
|
265
372
|
|
|
373
|
+
test("provider emits verbose session logs when enabled", async (t) => {
|
|
374
|
+
const relay = createRelayServer({
|
|
375
|
+
host: "127.0.0.1",
|
|
376
|
+
port: 0,
|
|
377
|
+
sessionTtlMs: 60_000,
|
|
378
|
+
frameCacheSize: 8,
|
|
379
|
+
});
|
|
380
|
+
const { port } = await relay.start();
|
|
381
|
+
t.after(async () => {
|
|
382
|
+
await relay.stop();
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
const logs: string[] = [];
|
|
386
|
+
const provider = new PrivateClawProvider({
|
|
387
|
+
providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
|
|
388
|
+
appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
|
|
389
|
+
bridge: new EchoBridge("OpenClaw bridge"),
|
|
390
|
+
defaultTtlMs: DEFAULT_SESSION_TTL_MS,
|
|
391
|
+
verboseController: { enabled: true },
|
|
392
|
+
onLog: (message) => {
|
|
393
|
+
logs.push(message);
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
await provider.connect();
|
|
397
|
+
t.after(async () => {
|
|
398
|
+
await provider.dispose();
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
const inviteBundle = await provider.createInviteBundle();
|
|
402
|
+
const invite = decodeInviteString(inviteBundle.inviteUri);
|
|
403
|
+
const appSocket = new WebSocket(invite.appWsUrl);
|
|
404
|
+
const attachedPromise = nextMessage(appSocket);
|
|
405
|
+
await waitForOpen(appSocket);
|
|
406
|
+
assert.equal((await attachedPromise).type, "relay:attached");
|
|
407
|
+
|
|
408
|
+
appSocket.send(
|
|
409
|
+
JSON.stringify({
|
|
410
|
+
type: "app:frame",
|
|
411
|
+
envelope: encryptPayload({
|
|
412
|
+
sessionId: invite.sessionId,
|
|
413
|
+
sessionKey: invite.sessionKey,
|
|
414
|
+
payload: {
|
|
415
|
+
kind: "client_hello",
|
|
416
|
+
appVersion: "flutter-test",
|
|
417
|
+
deviceLabel: "Verbose Simulator",
|
|
418
|
+
sentAt: new Date().toISOString(),
|
|
419
|
+
},
|
|
420
|
+
}),
|
|
421
|
+
}),
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
await nextMessages(appSocket, 2);
|
|
425
|
+
|
|
426
|
+
assert.ok(
|
|
427
|
+
logs.some((message) =>
|
|
428
|
+
message.includes(`[provider][verbose] session_created session=${invite.sessionId}`),
|
|
429
|
+
),
|
|
430
|
+
"verbose provider logging should include session creation details",
|
|
431
|
+
);
|
|
432
|
+
assert.ok(
|
|
433
|
+
logs.some((message) =>
|
|
434
|
+
message.includes(
|
|
435
|
+
`[provider][verbose] payload_in session=${invite.sessionId} kind=client_hello`,
|
|
436
|
+
),
|
|
437
|
+
),
|
|
438
|
+
"verbose provider logging should include inbound payload details",
|
|
439
|
+
);
|
|
440
|
+
assert.ok(
|
|
441
|
+
logs.some((message) =>
|
|
442
|
+
message.includes(`[provider][verbose] capabilities_out session=${invite.sessionId}`),
|
|
443
|
+
),
|
|
444
|
+
"verbose provider logging should include capabilities broadcasts",
|
|
445
|
+
);
|
|
446
|
+
assert.ok(
|
|
447
|
+
logs.some((message) =>
|
|
448
|
+
message.includes(
|
|
449
|
+
`[provider][verbose] payload_out session=${invite.sessionId} kind=provider_capabilities`,
|
|
450
|
+
),
|
|
451
|
+
),
|
|
452
|
+
"verbose provider logging should include outbound payload details",
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
appSocket.terminate();
|
|
456
|
+
});
|
|
457
|
+
|
|
266
458
|
test("provider can hand off an active session to a successor provider", async (t) => {
|
|
267
459
|
const relay = createRelayServer({
|
|
268
460
|
host: "127.0.0.1",
|
|
@@ -476,6 +668,195 @@ test("provider acknowledges voice uploads before forwarding transcript-derived r
|
|
|
476
668
|
appSocket.terminate();
|
|
477
669
|
});
|
|
478
670
|
|
|
671
|
+
test("provider prefers a direct audio transcriber over the bridge STT path", async (t) => {
|
|
672
|
+
const relay = createRelayServer({
|
|
673
|
+
host: "127.0.0.1",
|
|
674
|
+
port: 0,
|
|
675
|
+
sessionTtlMs: 60_000,
|
|
676
|
+
frameCacheSize: 8,
|
|
677
|
+
});
|
|
678
|
+
const { port } = await relay.start();
|
|
679
|
+
t.after(async () => {
|
|
680
|
+
await relay.stop();
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
const bridge = new VoiceTranscribingBridge();
|
|
684
|
+
const audioTranscriber = new DirectAudioTranscriber();
|
|
685
|
+
const provider = new PrivateClawProvider({
|
|
686
|
+
providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
|
|
687
|
+
appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
|
|
688
|
+
bridge,
|
|
689
|
+
audioTranscriber,
|
|
690
|
+
defaultTtlMs: DEFAULT_SESSION_TTL_MS,
|
|
691
|
+
welcomeMessage: "欢迎来到 PrivateClaw",
|
|
692
|
+
});
|
|
693
|
+
await provider.connect();
|
|
694
|
+
t.after(async () => {
|
|
695
|
+
await provider.dispose();
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
const inviteBundle = await provider.createInviteBundle();
|
|
699
|
+
const invite = decodeInviteString(inviteBundle.inviteUri);
|
|
700
|
+
|
|
701
|
+
const appUrl = new URL(invite.appWsUrl);
|
|
702
|
+
appUrl.searchParams.set("appId", "voice-app");
|
|
703
|
+
const appSocket = new WebSocket(appUrl.toString());
|
|
704
|
+
const attachedPromise = nextMessage(appSocket);
|
|
705
|
+
await waitForOpen(appSocket);
|
|
706
|
+
assert.equal((await attachedPromise).type, "relay:attached");
|
|
707
|
+
|
|
708
|
+
appSocket.send(
|
|
709
|
+
JSON.stringify({
|
|
710
|
+
type: "app:frame",
|
|
711
|
+
envelope: encryptPayload({
|
|
712
|
+
sessionId: invite.sessionId,
|
|
713
|
+
sessionKey: invite.sessionKey,
|
|
714
|
+
payload: {
|
|
715
|
+
kind: "client_hello",
|
|
716
|
+
appId: "voice-app",
|
|
717
|
+
displayName: "小明",
|
|
718
|
+
appVersion: "flutter-test",
|
|
719
|
+
deviceLabel: "Simulator",
|
|
720
|
+
sentAt: new Date().toISOString(),
|
|
721
|
+
},
|
|
722
|
+
}),
|
|
723
|
+
}),
|
|
724
|
+
);
|
|
725
|
+
await nextMessages(appSocket, 2);
|
|
726
|
+
|
|
727
|
+
appSocket.send(
|
|
728
|
+
JSON.stringify({
|
|
729
|
+
type: "app:frame",
|
|
730
|
+
envelope: encryptPayload({
|
|
731
|
+
sessionId: invite.sessionId,
|
|
732
|
+
sessionKey: invite.sessionKey,
|
|
733
|
+
payload: {
|
|
734
|
+
kind: "user_message",
|
|
735
|
+
appId: "voice-app",
|
|
736
|
+
displayName: "小明",
|
|
737
|
+
text: "",
|
|
738
|
+
attachments: [buildVoiceAttachment()],
|
|
739
|
+
clientMessageId: "voice-message-direct-stt",
|
|
740
|
+
sentAt: new Date().toISOString(),
|
|
741
|
+
},
|
|
742
|
+
}),
|
|
743
|
+
}),
|
|
744
|
+
);
|
|
745
|
+
|
|
746
|
+
const voiceFrames = await nextMessages(appSocket, 3);
|
|
747
|
+
const assistant = decryptRelayPayload(voiceFrames[2]!, invite);
|
|
748
|
+
assert.equal(assistant.kind, "assistant_message");
|
|
749
|
+
assert.match(assistant.text, /小明说:你好世界/u);
|
|
750
|
+
assert.deepEqual(audioTranscriber.transcriptionRequests, [
|
|
751
|
+
{
|
|
752
|
+
sessionId: invite.sessionId,
|
|
753
|
+
requestId: "voice-message-direct-stt",
|
|
754
|
+
},
|
|
755
|
+
]);
|
|
756
|
+
assert.deepEqual(bridge.transcriptionRequests, []);
|
|
757
|
+
assert.equal(bridge.conversationMessages.length, 1);
|
|
758
|
+
assert.match(bridge.conversationMessages[0] ?? "", /小明说:你好世界/u);
|
|
759
|
+
|
|
760
|
+
appSocket.terminate();
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
test("provider falls back to bridge STT after provider-side transcription fails", async (t) => {
|
|
764
|
+
const relay = createRelayServer({
|
|
765
|
+
host: "127.0.0.1",
|
|
766
|
+
port: 0,
|
|
767
|
+
sessionTtlMs: 60_000,
|
|
768
|
+
frameCacheSize: 8,
|
|
769
|
+
});
|
|
770
|
+
const { port } = await relay.start();
|
|
771
|
+
t.after(async () => {
|
|
772
|
+
await relay.stop();
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
const bridge = new VoiceTranscribingBridge();
|
|
776
|
+
const audioTranscriber = new FailingAudioTranscriber();
|
|
777
|
+
const provider = new PrivateClawProvider({
|
|
778
|
+
providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
|
|
779
|
+
appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
|
|
780
|
+
bridge,
|
|
781
|
+
audioTranscriber,
|
|
782
|
+
defaultTtlMs: DEFAULT_SESSION_TTL_MS,
|
|
783
|
+
welcomeMessage: "欢迎来到 PrivateClaw",
|
|
784
|
+
});
|
|
785
|
+
await provider.connect();
|
|
786
|
+
t.after(async () => {
|
|
787
|
+
await provider.dispose();
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
const inviteBundle = await provider.createInviteBundle();
|
|
791
|
+
const invite = decodeInviteString(inviteBundle.inviteUri);
|
|
792
|
+
|
|
793
|
+
const appUrl = new URL(invite.appWsUrl);
|
|
794
|
+
appUrl.searchParams.set("appId", "voice-app");
|
|
795
|
+
const appSocket = new WebSocket(appUrl.toString());
|
|
796
|
+
const attachedPromise = nextMessage(appSocket);
|
|
797
|
+
await waitForOpen(appSocket);
|
|
798
|
+
assert.equal((await attachedPromise).type, "relay:attached");
|
|
799
|
+
|
|
800
|
+
appSocket.send(
|
|
801
|
+
JSON.stringify({
|
|
802
|
+
type: "app:frame",
|
|
803
|
+
envelope: encryptPayload({
|
|
804
|
+
sessionId: invite.sessionId,
|
|
805
|
+
sessionKey: invite.sessionKey,
|
|
806
|
+
payload: {
|
|
807
|
+
kind: "client_hello",
|
|
808
|
+
appId: "voice-app",
|
|
809
|
+
displayName: "小明",
|
|
810
|
+
appVersion: "flutter-test",
|
|
811
|
+
deviceLabel: "Simulator",
|
|
812
|
+
sentAt: new Date().toISOString(),
|
|
813
|
+
},
|
|
814
|
+
}),
|
|
815
|
+
}),
|
|
816
|
+
);
|
|
817
|
+
await nextMessages(appSocket, 2);
|
|
818
|
+
|
|
819
|
+
appSocket.send(
|
|
820
|
+
JSON.stringify({
|
|
821
|
+
type: "app:frame",
|
|
822
|
+
envelope: encryptPayload({
|
|
823
|
+
sessionId: invite.sessionId,
|
|
824
|
+
sessionKey: invite.sessionKey,
|
|
825
|
+
payload: {
|
|
826
|
+
kind: "user_message",
|
|
827
|
+
appId: "voice-app",
|
|
828
|
+
displayName: "小明",
|
|
829
|
+
text: "",
|
|
830
|
+
attachments: [buildVoiceAttachment()],
|
|
831
|
+
clientMessageId: "voice-message-provider-fallback",
|
|
832
|
+
sentAt: new Date().toISOString(),
|
|
833
|
+
},
|
|
834
|
+
}),
|
|
835
|
+
}),
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
const voiceFrames = await nextMessages(appSocket, 3);
|
|
839
|
+
const assistant = decryptRelayPayload(voiceFrames[2]!, invite);
|
|
840
|
+
assert.equal(assistant.kind, "assistant_message");
|
|
841
|
+
assert.match(assistant.text, /小明说:你好世界/u);
|
|
842
|
+
assert.deepEqual(audioTranscriber.transcriptionRequests, [
|
|
843
|
+
{
|
|
844
|
+
sessionId: invite.sessionId,
|
|
845
|
+
requestId: "voice-message-provider-fallback",
|
|
846
|
+
},
|
|
847
|
+
]);
|
|
848
|
+
assert.deepEqual(bridge.transcriptionRequests, [
|
|
849
|
+
{
|
|
850
|
+
sessionId: invite.sessionId,
|
|
851
|
+
requestId: "voice-message-provider-fallback",
|
|
852
|
+
},
|
|
853
|
+
]);
|
|
854
|
+
assert.equal(bridge.conversationMessages.length, 1);
|
|
855
|
+
assert.match(bridge.conversationMessages[0] ?? "", /小明说:你好世界/u);
|
|
856
|
+
|
|
857
|
+
appSocket.terminate();
|
|
858
|
+
});
|
|
859
|
+
|
|
479
860
|
test("provider returns the current session QR only to the requesting participant", async (t) => {
|
|
480
861
|
const relay = createRelayServer({
|
|
481
862
|
host: "127.0.0.1",
|
|
@@ -945,6 +1326,7 @@ test("provider group sessions broadcast participant messages and assign unique l
|
|
|
945
1326
|
appId: "app-one",
|
|
946
1327
|
appVersion: "flutter-test",
|
|
947
1328
|
deviceLabel: "Tester One",
|
|
1329
|
+
supportsThinkingTrace: true,
|
|
948
1330
|
sentAt: new Date().toISOString(),
|
|
949
1331
|
},
|
|
950
1332
|
}),
|
|
@@ -978,6 +1360,7 @@ test("provider group sessions broadcast participant messages and assign unique l
|
|
|
978
1360
|
appId: "app-two",
|
|
979
1361
|
appVersion: "flutter-test",
|
|
980
1362
|
deviceLabel: "Tester Two",
|
|
1363
|
+
supportsThinkingTrace: true,
|
|
981
1364
|
sentAt: new Date().toISOString(),
|
|
982
1365
|
},
|
|
983
1366
|
}),
|
|
@@ -1052,6 +1435,166 @@ test("provider group sessions broadcast participant messages and assign unique l
|
|
|
1052
1435
|
await Promise.all([waitForClose(appOne), waitForClose(appTwo)]);
|
|
1053
1436
|
});
|
|
1054
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
|
+
|
|
1055
1598
|
test("provider group sessions broadcast raw voice first and only reply with the final assistant answer", async (t) => {
|
|
1056
1599
|
const relay = createRelayServer({
|
|
1057
1600
|
host: "127.0.0.1",
|
|
@@ -1612,6 +2155,142 @@ test("group sessions can mute and unmute bot replies without stopping participan
|
|
|
1612
2155
|
await Promise.all([waitForClose(appOne), waitForClose(appTwo)]);
|
|
1613
2156
|
});
|
|
1614
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
|
+
|
|
1615
2294
|
test("group sessions keep running when one participant leaves and later rejoins", async (t) => {
|
|
1616
2295
|
const relay = createRelayServer({
|
|
1617
2296
|
host: "127.0.0.1",
|