@privateclaw/privateclaw 0.1.16 → 0.1.17

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.
Files changed (39) hide show
  1. package/README.md +44 -1
  2. package/dist/audio-transcriber.d.ts +46 -0
  3. package/dist/audio-transcriber.js +433 -0
  4. package/dist/audio-transcriber.js.map +1 -0
  5. package/dist/bridges/openclaw-agent-bridge.d.ts +4 -1
  6. package/dist/bridges/openclaw-agent-bridge.js +81 -8
  7. package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
  8. package/dist/cli.js +57 -6
  9. package/dist/cli.js.map +1 -1
  10. package/dist/openclaw-plugin.js +150 -51
  11. package/dist/openclaw-plugin.js.map +1 -1
  12. package/dist/pair-daemon.d.ts +2 -0
  13. package/dist/pair-daemon.js +2 -0
  14. package/dist/pair-daemon.js.map +1 -1
  15. package/dist/provider.d.ts +2 -0
  16. package/dist/provider.js +103 -14
  17. package/dist/provider.js.map +1 -1
  18. package/dist/session-control.d.ts +7 -0
  19. package/dist/session-control.js +122 -0
  20. package/dist/session-control.js.map +1 -1
  21. package/dist/text.d.ts +2 -0
  22. package/dist/text.js +3 -1
  23. package/dist/text.js.map +1 -1
  24. package/dist/types.d.ts +8 -0
  25. package/package.json +1 -1
  26. package/src/audio-transcriber.test.ts +299 -0
  27. package/src/audio-transcriber.ts +615 -0
  28. package/src/bridges/openclaw-agent-bridge.test.ts +78 -13
  29. package/src/bridges/openclaw-agent-bridge.ts +109 -7
  30. package/src/cli.ts +73 -5
  31. package/src/openclaw-plugin.test.ts +12 -2
  32. package/src/openclaw-plugin.ts +191 -54
  33. package/src/pair-daemon.ts +4 -0
  34. package/src/provider.test.ts +304 -0
  35. package/src/provider.ts +146 -20
  36. package/src/session-control.test.ts +80 -0
  37. package/src/session-control.ts +151 -0
  38. package/src/text.ts +12 -2
  39. package/src/types.ts +12 -0
@@ -161,6 +161,36 @@ class VoiceTranscribingBridge {
161
161
  }
162
162
  }
163
163
 
164
+ class DirectAudioTranscriber {
165
+ readonly transcriptionRequests: Array<{ sessionId: string; requestId: string }> = [];
166
+
167
+ async transcribeAudioAttachments(params: {
168
+ sessionId: string;
169
+ requestId: string;
170
+ }): Promise<string> {
171
+ this.transcriptionRequests.push({
172
+ sessionId: params.sessionId,
173
+ requestId: params.requestId,
174
+ });
175
+ return "你好世界";
176
+ }
177
+ }
178
+
179
+ class FailingAudioTranscriber {
180
+ readonly transcriptionRequests: Array<{ sessionId: string; requestId: string }> = [];
181
+
182
+ async transcribeAudioAttachments(params: {
183
+ sessionId: string;
184
+ requestId: string;
185
+ }): Promise<string> {
186
+ this.transcriptionRequests.push({
187
+ sessionId: params.sessionId,
188
+ requestId: params.requestId,
189
+ });
190
+ throw new Error("local STT failed");
191
+ }
192
+ }
193
+
164
194
  function buildVoiceAttachment() {
165
195
  return {
166
196
  id: "voice-attachment-1",
@@ -263,6 +293,91 @@ test("provider creates one-time invites and replies through the encrypted relay"
263
293
  appSocket.terminate();
264
294
  });
265
295
 
296
+ test("provider emits verbose session logs when enabled", async (t) => {
297
+ const relay = createRelayServer({
298
+ host: "127.0.0.1",
299
+ port: 0,
300
+ sessionTtlMs: 60_000,
301
+ frameCacheSize: 8,
302
+ });
303
+ const { port } = await relay.start();
304
+ t.after(async () => {
305
+ await relay.stop();
306
+ });
307
+
308
+ const logs: string[] = [];
309
+ const provider = new PrivateClawProvider({
310
+ providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
311
+ appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
312
+ bridge: new EchoBridge("OpenClaw bridge"),
313
+ defaultTtlMs: DEFAULT_SESSION_TTL_MS,
314
+ verboseController: { enabled: true },
315
+ onLog: (message) => {
316
+ logs.push(message);
317
+ },
318
+ });
319
+ await provider.connect();
320
+ t.after(async () => {
321
+ await provider.dispose();
322
+ });
323
+
324
+ const inviteBundle = await provider.createInviteBundle();
325
+ const invite = decodeInviteString(inviteBundle.inviteUri);
326
+ const appSocket = new WebSocket(invite.appWsUrl);
327
+ const attachedPromise = nextMessage(appSocket);
328
+ await waitForOpen(appSocket);
329
+ assert.equal((await attachedPromise).type, "relay:attached");
330
+
331
+ appSocket.send(
332
+ JSON.stringify({
333
+ type: "app:frame",
334
+ envelope: encryptPayload({
335
+ sessionId: invite.sessionId,
336
+ sessionKey: invite.sessionKey,
337
+ payload: {
338
+ kind: "client_hello",
339
+ appVersion: "flutter-test",
340
+ deviceLabel: "Verbose Simulator",
341
+ sentAt: new Date().toISOString(),
342
+ },
343
+ }),
344
+ }),
345
+ );
346
+
347
+ await nextMessages(appSocket, 2);
348
+
349
+ assert.ok(
350
+ logs.some((message) =>
351
+ message.includes(`[provider][verbose] session_created session=${invite.sessionId}`),
352
+ ),
353
+ "verbose provider logging should include session creation details",
354
+ );
355
+ assert.ok(
356
+ logs.some((message) =>
357
+ message.includes(
358
+ `[provider][verbose] payload_in session=${invite.sessionId} kind=client_hello`,
359
+ ),
360
+ ),
361
+ "verbose provider logging should include inbound payload details",
362
+ );
363
+ assert.ok(
364
+ logs.some((message) =>
365
+ message.includes(`[provider][verbose] capabilities_out session=${invite.sessionId}`),
366
+ ),
367
+ "verbose provider logging should include capabilities broadcasts",
368
+ );
369
+ assert.ok(
370
+ logs.some((message) =>
371
+ message.includes(
372
+ `[provider][verbose] payload_out session=${invite.sessionId} kind=provider_capabilities`,
373
+ ),
374
+ ),
375
+ "verbose provider logging should include outbound payload details",
376
+ );
377
+
378
+ appSocket.terminate();
379
+ });
380
+
266
381
  test("provider can hand off an active session to a successor provider", async (t) => {
267
382
  const relay = createRelayServer({
268
383
  host: "127.0.0.1",
@@ -476,6 +591,195 @@ test("provider acknowledges voice uploads before forwarding transcript-derived r
476
591
  appSocket.terminate();
477
592
  });
478
593
 
594
+ test("provider prefers a direct audio transcriber over the bridge STT path", async (t) => {
595
+ const relay = createRelayServer({
596
+ host: "127.0.0.1",
597
+ port: 0,
598
+ sessionTtlMs: 60_000,
599
+ frameCacheSize: 8,
600
+ });
601
+ const { port } = await relay.start();
602
+ t.after(async () => {
603
+ await relay.stop();
604
+ });
605
+
606
+ const bridge = new VoiceTranscribingBridge();
607
+ const audioTranscriber = new DirectAudioTranscriber();
608
+ const provider = new PrivateClawProvider({
609
+ providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
610
+ appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
611
+ bridge,
612
+ audioTranscriber,
613
+ defaultTtlMs: DEFAULT_SESSION_TTL_MS,
614
+ welcomeMessage: "欢迎来到 PrivateClaw",
615
+ });
616
+ await provider.connect();
617
+ t.after(async () => {
618
+ await provider.dispose();
619
+ });
620
+
621
+ const inviteBundle = await provider.createInviteBundle();
622
+ const invite = decodeInviteString(inviteBundle.inviteUri);
623
+
624
+ const appUrl = new URL(invite.appWsUrl);
625
+ appUrl.searchParams.set("appId", "voice-app");
626
+ const appSocket = new WebSocket(appUrl.toString());
627
+ const attachedPromise = nextMessage(appSocket);
628
+ await waitForOpen(appSocket);
629
+ assert.equal((await attachedPromise).type, "relay:attached");
630
+
631
+ appSocket.send(
632
+ JSON.stringify({
633
+ type: "app:frame",
634
+ envelope: encryptPayload({
635
+ sessionId: invite.sessionId,
636
+ sessionKey: invite.sessionKey,
637
+ payload: {
638
+ kind: "client_hello",
639
+ appId: "voice-app",
640
+ displayName: "小明",
641
+ appVersion: "flutter-test",
642
+ deviceLabel: "Simulator",
643
+ sentAt: new Date().toISOString(),
644
+ },
645
+ }),
646
+ }),
647
+ );
648
+ await nextMessages(appSocket, 2);
649
+
650
+ appSocket.send(
651
+ JSON.stringify({
652
+ type: "app:frame",
653
+ envelope: encryptPayload({
654
+ sessionId: invite.sessionId,
655
+ sessionKey: invite.sessionKey,
656
+ payload: {
657
+ kind: "user_message",
658
+ appId: "voice-app",
659
+ displayName: "小明",
660
+ text: "",
661
+ attachments: [buildVoiceAttachment()],
662
+ clientMessageId: "voice-message-direct-stt",
663
+ sentAt: new Date().toISOString(),
664
+ },
665
+ }),
666
+ }),
667
+ );
668
+
669
+ const voiceFrames = await nextMessages(appSocket, 3);
670
+ const assistant = decryptRelayPayload(voiceFrames[2]!, invite);
671
+ assert.equal(assistant.kind, "assistant_message");
672
+ assert.match(assistant.text, /小明说:你好世界/u);
673
+ assert.deepEqual(audioTranscriber.transcriptionRequests, [
674
+ {
675
+ sessionId: invite.sessionId,
676
+ requestId: "voice-message-direct-stt",
677
+ },
678
+ ]);
679
+ assert.deepEqual(bridge.transcriptionRequests, []);
680
+ assert.equal(bridge.conversationMessages.length, 1);
681
+ assert.match(bridge.conversationMessages[0] ?? "", /小明说:你好世界/u);
682
+
683
+ appSocket.terminate();
684
+ });
685
+
686
+ test("provider falls back to bridge STT after provider-side transcription fails", async (t) => {
687
+ const relay = createRelayServer({
688
+ host: "127.0.0.1",
689
+ port: 0,
690
+ sessionTtlMs: 60_000,
691
+ frameCacheSize: 8,
692
+ });
693
+ const { port } = await relay.start();
694
+ t.after(async () => {
695
+ await relay.stop();
696
+ });
697
+
698
+ const bridge = new VoiceTranscribingBridge();
699
+ const audioTranscriber = new FailingAudioTranscriber();
700
+ const provider = new PrivateClawProvider({
701
+ providerWsUrl: `ws://127.0.0.1:${port}/ws/provider`,
702
+ appWsUrl: `ws://127.0.0.1:${port}/ws/app`,
703
+ bridge,
704
+ audioTranscriber,
705
+ defaultTtlMs: DEFAULT_SESSION_TTL_MS,
706
+ welcomeMessage: "欢迎来到 PrivateClaw",
707
+ });
708
+ await provider.connect();
709
+ t.after(async () => {
710
+ await provider.dispose();
711
+ });
712
+
713
+ const inviteBundle = await provider.createInviteBundle();
714
+ const invite = decodeInviteString(inviteBundle.inviteUri);
715
+
716
+ const appUrl = new URL(invite.appWsUrl);
717
+ appUrl.searchParams.set("appId", "voice-app");
718
+ const appSocket = new WebSocket(appUrl.toString());
719
+ const attachedPromise = nextMessage(appSocket);
720
+ await waitForOpen(appSocket);
721
+ assert.equal((await attachedPromise).type, "relay:attached");
722
+
723
+ appSocket.send(
724
+ JSON.stringify({
725
+ type: "app:frame",
726
+ envelope: encryptPayload({
727
+ sessionId: invite.sessionId,
728
+ sessionKey: invite.sessionKey,
729
+ payload: {
730
+ kind: "client_hello",
731
+ appId: "voice-app",
732
+ displayName: "小明",
733
+ appVersion: "flutter-test",
734
+ deviceLabel: "Simulator",
735
+ sentAt: new Date().toISOString(),
736
+ },
737
+ }),
738
+ }),
739
+ );
740
+ await nextMessages(appSocket, 2);
741
+
742
+ appSocket.send(
743
+ JSON.stringify({
744
+ type: "app:frame",
745
+ envelope: encryptPayload({
746
+ sessionId: invite.sessionId,
747
+ sessionKey: invite.sessionKey,
748
+ payload: {
749
+ kind: "user_message",
750
+ appId: "voice-app",
751
+ displayName: "小明",
752
+ text: "",
753
+ attachments: [buildVoiceAttachment()],
754
+ clientMessageId: "voice-message-provider-fallback",
755
+ sentAt: new Date().toISOString(),
756
+ },
757
+ }),
758
+ }),
759
+ );
760
+
761
+ const voiceFrames = await nextMessages(appSocket, 3);
762
+ const assistant = decryptRelayPayload(voiceFrames[2]!, invite);
763
+ assert.equal(assistant.kind, "assistant_message");
764
+ assert.match(assistant.text, /小明说:你好世界/u);
765
+ assert.deepEqual(audioTranscriber.transcriptionRequests, [
766
+ {
767
+ sessionId: invite.sessionId,
768
+ requestId: "voice-message-provider-fallback",
769
+ },
770
+ ]);
771
+ assert.deepEqual(bridge.transcriptionRequests, [
772
+ {
773
+ sessionId: invite.sessionId,
774
+ requestId: "voice-message-provider-fallback",
775
+ },
776
+ ]);
777
+ assert.equal(bridge.conversationMessages.length, 1);
778
+ assert.match(bridge.conversationMessages[0] ?? "", /小明说:你好世界/u);
779
+
780
+ appSocket.terminate();
781
+ });
782
+
479
783
  test("provider returns the current session QR only to the requesting participant", async (t) => {
480
784
  const relay = createRelayServer({
481
785
  host: "127.0.0.1",
package/src/provider.ts CHANGED
@@ -42,7 +42,7 @@ import type {
42
42
  ProviderSessionState,
43
43
  } from "./types.js";
44
44
 
45
- export const DEFAULT_SESSION_TTL_MS = 8 * 60 * 60 * 1000;
45
+ export const DEFAULT_SESSION_TTL_MS = 24 * 60 * 60 * 1000;
46
46
  const RENEW_SESSION_TTL_MS = DEFAULT_SESSION_TTL_MS;
47
47
  const SESSION_RENEWAL_REMINDER_WINDOW_MS = 30 * 60 * 1000;
48
48
  const PARTICIPANT_LABEL_MAX_CHARS = 12;
@@ -93,6 +93,14 @@ function nowIso(): string {
93
93
  return new Date().toISOString();
94
94
  }
95
95
 
96
+ function readNonEmptyString(value: unknown): string | undefined {
97
+ if (typeof value !== "string") {
98
+ return undefined;
99
+ }
100
+ const trimmed = value.trim();
101
+ return trimmed === "" ? undefined : trimmed;
102
+ }
103
+
96
104
  function buildMessageId(prefix: string): string {
97
105
  return `${prefix}-${randomUUID()}`;
98
106
  }
@@ -193,6 +201,35 @@ function cloneConversationTurn(
193
201
  };
194
202
  }
195
203
 
204
+ function countPayloadAttachments(payload: Record<string, unknown>): number {
205
+ return Array.isArray(payload.attachments) ? payload.attachments.length : 0;
206
+ }
207
+
208
+ function toUnknownRecord(value: unknown): Record<string, unknown> {
209
+ return value as Record<string, unknown>;
210
+ }
211
+
212
+ function summarizePayload(
213
+ payload: Parameters<typeof encryptPayload>[0]["payload"],
214
+ ): string {
215
+ const record = toUnknownRecord(payload);
216
+ const text = typeof record.text === "string" ? record.text : "";
217
+ const message = typeof record.message === "string" ? record.message : "";
218
+ const senderAppId = readNonEmptyString(record.senderAppId);
219
+ const targetAppId = readNonEmptyString(record.targetAppId);
220
+ const replyTo = readNonEmptyString(record.replyTo);
221
+ return [
222
+ `kind=${payload.kind}`,
223
+ `textChars=${text.length}`,
224
+ `messageChars=${message.length}`,
225
+ `attachments=${countPayloadAttachments(record)}`,
226
+ `replyTo=${JSON.stringify(replyTo ?? "none")}`,
227
+ `senderAppId=${JSON.stringify(senderAppId ?? "none")}`,
228
+ `targetAppId=${JSON.stringify(targetAppId ?? "broadcast")}`,
229
+ `pending=${record.pending === true}`,
230
+ ].join(" ");
231
+ }
232
+
196
233
  function buildRelayLabel(appWsUrl: string): string | undefined {
197
234
  try {
198
235
  const url = new URL(appWsUrl);
@@ -260,13 +297,13 @@ function buildRenewalReminderMessage(session: ProviderSessionState): string {
260
297
  const command = "/renew-session";
261
298
  if (session.groupMode) {
262
299
  return formatBilingualText(
263
- `这个 PrivateClaw 群聊会话将在 30 分钟内过期(${session.invite.expiresAt})。任意参与者都可以发送 ${command} 将它延长 8 小时。`,
264
- `This PrivateClaw group session will expire in less than 30 minutes (at ${session.invite.expiresAt}). Any participant can send ${command} to extend it by 8 hours.`,
300
+ `这个 PrivateClaw 群聊会话将在 30 分钟内过期(${session.invite.expiresAt})。任意参与者都可以发送 ${command} 将它延长 24 小时。`,
301
+ `This PrivateClaw group session will expire in less than 30 minutes (at ${session.invite.expiresAt}). Any participant can send ${command} to extend it by 24 hours.`,
265
302
  );
266
303
  }
267
304
  return formatBilingualText(
268
- `这个 PrivateClaw 会话将在 30 分钟内过期(${session.invite.expiresAt})。发送 ${command} 可将它延长 8 小时。`,
269
- `This PrivateClaw session will expire in less than 30 minutes (at ${session.invite.expiresAt}). Send ${command} to extend it by 8 hours.`,
305
+ `这个 PrivateClaw 会话将在 30 分钟内过期(${session.invite.expiresAt})。发送 ${command} 可将它延长 24 小时。`,
306
+ `This PrivateClaw session will expire in less than 30 minutes (at ${session.invite.expiresAt}). Send ${command} to extend it by 24 hours.`,
270
307
  );
271
308
  }
272
309
 
@@ -580,8 +617,25 @@ export class PrivateClawProvider {
580
617
  });
581
618
  }
582
619
 
620
+ private isVerboseLoggingEnabled(): boolean {
621
+ return this.options.verboseController?.enabled === true;
622
+ }
623
+
624
+ private verboseLog(message: string): void {
625
+ if (!this.isVerboseLoggingEnabled()) {
626
+ return;
627
+ }
628
+ this.options.onLog?.(`[provider][verbose] ${message}`);
629
+ }
630
+
583
631
  async connect(): Promise<void> {
632
+ this.verboseLog(
633
+ `connect_start providerId=${this.relayClient.getProviderId()} relay=${JSON.stringify(this.options.providerWsUrl)}`,
634
+ );
584
635
  await this.relayClient.connect();
636
+ this.verboseLog(
637
+ `connect_complete providerId=${this.relayClient.getProviderId()} activeSessions=${this.sessions.size}`,
638
+ );
585
639
  }
586
640
 
587
641
  async dispose(params?: { closeSessions?: boolean }): Promise<void> {
@@ -750,10 +804,29 @@ export class PrivateClawProvider {
750
804
  ): Promise<PreparedUserMessage> {
751
805
  const allAttachments = payload.attachments ?? [];
752
806
  const audioAttachments = allAttachments.filter(isAudioAttachment);
807
+ const providerAudioTranscriber = this.options.audioTranscriber;
808
+ const bridgeAudioTranscriber = this.options.bridge.transcribeAudioAttachments
809
+ ? {
810
+ transcribeAudioAttachments: this.options.bridge.transcribeAudioAttachments.bind(
811
+ this.options.bridge,
812
+ ),
813
+ }
814
+ : undefined;
815
+ const availableAudioTranscribers = [
816
+ ...(providerAudioTranscriber
817
+ ? [{ via: "provider" as const, transcriber: providerAudioTranscriber }]
818
+ : []),
819
+ ...(bridgeAudioTranscriber
820
+ ? [{ via: "bridge" as const, transcriber: bridgeAudioTranscriber }]
821
+ : []),
822
+ ];
753
823
  if (
754
824
  audioAttachments.length === 0 ||
755
- !this.options.bridge.transcribeAudioAttachments
825
+ availableAudioTranscribers.length === 0
756
826
  ) {
827
+ this.verboseLog(
828
+ `prepared_user_message session=${session.invite.sessionId} request=${payload.clientMessageId} voiceTranscribed=false textChars=${payload.text.length} attachments=${allAttachments.length} bridgeAttachments=${allAttachments.length}`,
829
+ );
757
830
  return {
758
831
  text: payload.text,
759
832
  ...(allAttachments.length > 0 ? { attachments: allAttachments } : {}),
@@ -761,18 +834,42 @@ export class PrivateClawProvider {
761
834
  };
762
835
  }
763
836
 
764
- this.options.onLog?.(
765
- `[provider] voice_transcription_start session=${session.invite.sessionId} request=${payload.clientMessageId} audioAttachments=${audioAttachments.length}`,
766
- );
767
- const transcript = (
768
- await this.options.bridge.transcribeAudioAttachments({
769
- sessionId: session.invite.sessionId,
770
- requestId: payload.clientMessageId,
771
- attachments: audioAttachments,
772
- })
773
- ).trim();
774
- if (transcript === "") {
775
- throw new Error("OpenClaw STT returned an empty transcript.");
837
+ let transcript = "";
838
+ let transcriptVia: "provider" | "bridge" | undefined;
839
+ const transcriptionFailures: string[] = [];
840
+ for (let index = 0; index < availableAudioTranscribers.length; index += 1) {
841
+ const candidate = availableAudioTranscribers[index]!;
842
+ const nextCandidate = availableAudioTranscribers[index + 1];
843
+ this.options.onLog?.(
844
+ `[provider] voice_transcription_start session=${session.invite.sessionId} request=${payload.clientMessageId} audioAttachments=${audioAttachments.length} via=${candidate.via}`,
845
+ );
846
+ try {
847
+ transcript = (
848
+ await candidate.transcriber.transcribeAudioAttachments({
849
+ sessionId: session.invite.sessionId,
850
+ requestId: payload.clientMessageId,
851
+ attachments: audioAttachments,
852
+ })
853
+ ).trim();
854
+ if (transcript === "") {
855
+ throw new Error("OpenClaw STT returned an empty transcript.");
856
+ }
857
+ transcriptVia = candidate.via;
858
+ break;
859
+ } catch (error) {
860
+ const detail = error instanceof Error ? error.message : String(error);
861
+ transcriptionFailures.push(`${candidate.via}: ${detail}`);
862
+ if (nextCandidate) {
863
+ this.options.onLog?.(
864
+ `[provider] voice_transcription_fallback session=${session.invite.sessionId} request=${payload.clientMessageId} from=${candidate.via} to=${nextCandidate.via} reason=${JSON.stringify(detail.slice(0, 300))}`,
865
+ );
866
+ }
867
+ }
868
+ }
869
+ if (!transcriptVia) {
870
+ throw new Error(
871
+ `OpenClaw STT failed for ${payload.clientMessageId}: ${transcriptionFailures.join(" | ")}`,
872
+ );
776
873
  }
777
874
 
778
875
  const text = mergeVoiceTranscriptText(transcript, payload.text);
@@ -784,7 +881,10 @@ export class PrivateClawProvider {
784
881
  (attachment) => !isAudioAttachment(attachment),
785
882
  );
786
883
  this.options.onLog?.(
787
- `[provider] voice_transcription_complete session=${session.invite.sessionId} request=${payload.clientMessageId} transcriptChars=${transcript.length} passthroughAttachments=${passthroughAttachments.length}`,
884
+ `[provider] voice_transcription_complete session=${session.invite.sessionId} request=${payload.clientMessageId} transcriptChars=${transcript.length} passthroughAttachments=${passthroughAttachments.length} via=${transcriptVia}`,
885
+ );
886
+ this.verboseLog(
887
+ `prepared_user_message session=${session.invite.sessionId} request=${payload.clientMessageId} voiceTranscribed=true transcriptChars=${transcript.length} textChars=${payload.text.length} passthroughAttachments=${passthroughAttachments.length} bridgeTextChars=${buildVoiceBridgePromptText(speakerName, text).length}`,
788
888
  );
789
889
  return {
790
890
  text: payload.text,
@@ -885,6 +985,9 @@ export class PrivateClawProvider {
885
985
  lastSeenAt: params.sentAt,
886
986
  };
887
987
  session.participants.set(normalizedAppId, participant);
988
+ this.verboseLog(
989
+ `participant_upsert session=${sessionId} appId=${JSON.stringify(normalizedAppId)} isNew=false displayName=${JSON.stringify(participant.displayName)} participants=${session.participants.size}`,
990
+ );
888
991
  return { participant, isNew: false };
889
992
  }
890
993
 
@@ -902,6 +1005,9 @@ export class PrivateClawProvider {
902
1005
  lastSeenAt: params.sentAt,
903
1006
  };
904
1007
  session.participants.set(normalizedAppId, participant);
1008
+ this.verboseLog(
1009
+ `participant_upsert session=${sessionId} appId=${JSON.stringify(normalizedAppId)} isNew=true displayName=${JSON.stringify(participant.displayName)} participants=${session.participants.size}`,
1010
+ );
905
1011
  return { participant, isNew: true };
906
1012
  }
907
1013
 
@@ -911,6 +1017,9 @@ export class PrivateClawProvider {
911
1017
  payload: Parameters<typeof encryptPayload>[0]["payload"],
912
1018
  targetAppId?: string,
913
1019
  ): Promise<void> {
1020
+ this.verboseLog(
1021
+ `payload_out session=${sessionId} ${summarizePayload(payload)} target=${JSON.stringify(targetAppId ?? "broadcast")}`,
1022
+ );
914
1023
  await this.relayClient.sendFrame(
915
1024
  sessionId,
916
1025
  encryptPayload({
@@ -1262,13 +1371,17 @@ export class PrivateClawProvider {
1262
1371
  const currentParticipant = params?.targetAppId
1263
1372
  ? session.participants.get(params.targetAppId)
1264
1373
  : undefined;
1374
+ const commands = await this.listAvailableCommands(session);
1375
+ this.verboseLog(
1376
+ `capabilities_out session=${sessionId} targetAppId=${JSON.stringify(params?.targetAppId ?? "broadcast")} includeCurrentIdentity=${params?.includeCurrentIdentity === true} commands=${commands.length} participants=${session.participants.size} groupMode=${session.groupMode}`,
1377
+ );
1265
1378
  await this.sendPayload(sessionId, {
1266
1379
  kind: "provider_capabilities",
1267
1380
  sentAt: nowIso(),
1268
1381
  expiresAt: session.invite.expiresAt,
1269
1382
  ...(session.groupMode ? { groupMode: true } : {}),
1270
1383
  ...(session.groupMode ? { botMuted: session.botMuted } : {}),
1271
- commands: await this.listAvailableCommands(session),
1384
+ commands,
1272
1385
  ...(session.groupMode
1273
1386
  ? { participants: this.listParticipants(session) }
1274
1387
  : {}),
@@ -1289,6 +1402,9 @@ export class PrivateClawProvider {
1289
1402
  targetAppId: string,
1290
1403
  ): Promise<void> {
1291
1404
  const session = this.requireSession(sessionId);
1405
+ this.verboseLog(
1406
+ `history_snapshot_out session=${sessionId} targetAppId=${JSON.stringify(targetAppId)} turns=${session.history.length}`,
1407
+ );
1292
1408
  for (const turn of session.history) {
1293
1409
  switch (turn.role) {
1294
1410
  case "assistant":
@@ -1391,6 +1507,10 @@ export class PrivateClawProvider {
1391
1507
  sessionKey: session.invite.sessionKey,
1392
1508
  envelope,
1393
1509
  });
1510
+ const payloadRecord = toUnknownRecord(payload);
1511
+ this.verboseLog(
1512
+ `payload_in session=${sessionId} kind=${payload.kind} state=${session.state} appId=${JSON.stringify(readNonEmptyString(payloadRecord.appId) ?? "none")} textChars=${typeof payloadRecord.text === "string" ? payloadRecord.text.length : 0} attachments=${countPayloadAttachments(payloadRecord)}`,
1513
+ );
1394
1514
 
1395
1515
  switch (payload.kind) {
1396
1516
  case "client_hello": {
@@ -1416,6 +1536,9 @@ export class PrivateClawProvider {
1416
1536
  const participant = participantState.participant;
1417
1537
  const wasAwaitingHello = session.state !== "active";
1418
1538
  const wasRenewing = Boolean(session.pendingRenewal);
1539
+ this.verboseLog(
1540
+ `client_hello_processed session=${sessionId} appId=${JSON.stringify(participant.appId)} isNew=${participantState.isNew} participants=${session.participants.size} awaitingHello=${wasAwaitingHello} renewing=${wasRenewing} groupMode=${session.groupMode}`,
1541
+ );
1419
1542
  session.state = "active";
1420
1543
  if (wasRenewing) {
1421
1544
  session.history.push({
@@ -1963,6 +2086,9 @@ export class PrivateClawProvider {
1963
2086
  state: "awaiting_hello",
1964
2087
  });
1965
2088
  this.scheduleRenewalReminder(sessionId);
2089
+ this.verboseLog(
2090
+ `session_created session=${sessionId} groupMode=${groupMode} label=${JSON.stringify(params?.label ?? "")} expiresAt=${JSON.stringify(expiresAt)} relayLabel=${JSON.stringify(relayLabel ?? "")} ttlMs=${params?.ttlMs ?? this.options.defaultTtlMs ?? DEFAULT_SESSION_TTL_MS}`,
2091
+ );
1966
2092
  return this.buildInviteBundleForInvite(invite);
1967
2093
  }
1968
2094