@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.
Files changed (42) 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/openai-compatible-bridge.js +1 -0
  6. package/dist/bridges/openai-compatible-bridge.js.map +1 -1
  7. package/dist/bridges/openclaw-agent-bridge.d.ts +10 -2
  8. package/dist/bridges/openclaw-agent-bridge.js +632 -73
  9. package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
  10. package/dist/cli.js +57 -6
  11. package/dist/cli.js.map +1 -1
  12. package/dist/openclaw-plugin.js +150 -51
  13. package/dist/openclaw-plugin.js.map +1 -1
  14. package/dist/pair-daemon.d.ts +2 -0
  15. package/dist/pair-daemon.js +2 -0
  16. package/dist/pair-daemon.js.map +1 -1
  17. package/dist/provider.d.ts +14 -1
  18. package/dist/provider.js +262 -20
  19. package/dist/provider.js.map +1 -1
  20. package/dist/session-control.d.ts +7 -0
  21. package/dist/session-control.js +122 -0
  22. package/dist/session-control.js.map +1 -1
  23. package/dist/text.d.ts +2 -0
  24. package/dist/text.js +3 -1
  25. package/dist/text.js.map +1 -1
  26. package/dist/types.d.ts +21 -2
  27. package/package.json +2 -2
  28. package/src/audio-transcriber.test.ts +299 -0
  29. package/src/audio-transcriber.ts +615 -0
  30. package/src/bridges/openai-compatible-bridge.ts +1 -0
  31. package/src/bridges/openclaw-agent-bridge.test.ts +644 -7
  32. package/src/bridges/openclaw-agent-bridge.ts +817 -81
  33. package/src/cli.ts +73 -5
  34. package/src/openclaw-plugin.test.ts +12 -2
  35. package/src/openclaw-plugin.ts +191 -54
  36. package/src/pair-daemon.ts +4 -0
  37. package/src/provider.test.ts +679 -0
  38. package/src/provider.ts +349 -28
  39. package/src/session-control.test.ts +80 -0
  40. package/src/session-control.ts +151 -0
  41. package/src/text.ts +12 -2
  42. package/src/types.ts +29 -1
package/src/provider.ts CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  type PrivateClawInvite,
10
10
  type PrivateClawParticipant,
11
11
  type PrivateClawSlashCommand,
12
+ type PrivateClawThinkingEntry,
13
+ type PrivateClawThinkingStatus,
12
14
  type UserMessagePayload,
13
15
  } from "@privateclaw/protocol";
14
16
  import QRCode from "qrcode";
@@ -42,7 +44,7 @@ import type {
42
44
  ProviderSessionState,
43
45
  } from "./types.js";
44
46
 
45
- export const DEFAULT_SESSION_TTL_MS = 8 * 60 * 60 * 1000;
47
+ export const DEFAULT_SESSION_TTL_MS = 24 * 60 * 60 * 1000;
46
48
  const RENEW_SESSION_TTL_MS = DEFAULT_SESSION_TTL_MS;
47
49
  const SESSION_RENEWAL_REMINDER_WINDOW_MS = 30 * 60 * 1000;
48
50
  const PARTICIPANT_LABEL_MAX_CHARS = 12;
@@ -93,6 +95,14 @@ function nowIso(): string {
93
95
  return new Date().toISOString();
94
96
  }
95
97
 
98
+ function readNonEmptyString(value: unknown): string | undefined {
99
+ if (typeof value !== "string") {
100
+ return undefined;
101
+ }
102
+ const trimmed = value.trim();
103
+ return trimmed === "" ? undefined : trimmed;
104
+ }
105
+
96
106
  function buildMessageId(prefix: string): string {
97
107
  return `${prefix}-${randomUUID()}`;
98
108
  }
@@ -101,6 +111,18 @@ function buildPendingAssistantMessageId(replyTo: string): string {
101
111
  return `pending-${replyTo}`;
102
112
  }
103
113
 
114
+ function buildThinkingMessageId(replyTo: string): string {
115
+ return `thinking-${replyTo}`;
116
+ }
117
+
118
+ function cloneThinkingEntry(
119
+ entry: PrivateClawThinkingEntry,
120
+ ): PrivateClawThinkingEntry {
121
+ return {
122
+ ...entry,
123
+ };
124
+ }
125
+
104
126
  function sanitizeParticipantLabel(raw: string | undefined): string | undefined {
105
127
  if (!raw) {
106
128
  return undefined;
@@ -190,9 +212,43 @@ function cloneConversationTurn(
190
212
  })),
191
213
  }
192
214
  : {}),
215
+ ...(turn.thinkingEntries
216
+ ? {
217
+ thinkingEntries: turn.thinkingEntries.map(cloneThinkingEntry),
218
+ }
219
+ : {}),
193
220
  };
194
221
  }
195
222
 
223
+ function countPayloadAttachments(payload: Record<string, unknown>): number {
224
+ return Array.isArray(payload.attachments) ? payload.attachments.length : 0;
225
+ }
226
+
227
+ function toUnknownRecord(value: unknown): Record<string, unknown> {
228
+ return value as Record<string, unknown>;
229
+ }
230
+
231
+ function summarizePayload(
232
+ payload: Parameters<typeof encryptPayload>[0]["payload"],
233
+ ): string {
234
+ const record = toUnknownRecord(payload);
235
+ const text = typeof record.text === "string" ? record.text : "";
236
+ const message = typeof record.message === "string" ? record.message : "";
237
+ const senderAppId = readNonEmptyString(record.senderAppId);
238
+ const targetAppId = readNonEmptyString(record.targetAppId);
239
+ const replyTo = readNonEmptyString(record.replyTo);
240
+ return [
241
+ `kind=${payload.kind}`,
242
+ `textChars=${text.length}`,
243
+ `messageChars=${message.length}`,
244
+ `attachments=${countPayloadAttachments(record)}`,
245
+ `replyTo=${JSON.stringify(replyTo ?? "none")}`,
246
+ `senderAppId=${JSON.stringify(senderAppId ?? "none")}`,
247
+ `targetAppId=${JSON.stringify(targetAppId ?? "broadcast")}`,
248
+ `pending=${record.pending === true}`,
249
+ ].join(" ");
250
+ }
251
+
196
252
  function buildRelayLabel(appWsUrl: string): string | undefined {
197
253
  try {
198
254
  const url = new URL(appWsUrl);
@@ -260,13 +316,13 @@ function buildRenewalReminderMessage(session: ProviderSessionState): string {
260
316
  const command = "/renew-session";
261
317
  if (session.groupMode) {
262
318
  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.`,
319
+ `这个 PrivateClaw 群聊会话将在 30 分钟内过期(${session.invite.expiresAt})。任意参与者都可以发送 ${command} 将它延长 24 小时。`,
320
+ `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
321
  );
266
322
  }
267
323
  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.`,
324
+ `这个 PrivateClaw 会话将在 30 分钟内过期(${session.invite.expiresAt})。发送 ${command} 可将它延长 24 小时。`,
325
+ `This PrivateClaw session will expire in less than 30 minutes (at ${session.invite.expiresAt}). Send ${command} to extend it by 24 hours.`,
270
326
  );
271
327
  }
272
328
 
@@ -310,6 +366,17 @@ function formatBridgeHistoryTurn(
310
366
  };
311
367
  }
312
368
 
369
+ function normalizeBridgeSlashCommandText(text: string): string | undefined {
370
+ const trimmed = text.trim();
371
+ return trimmed.startsWith("/") ? trimmed : undefined;
372
+ }
373
+
374
+ function cloneThinkingEntries(
375
+ entries: ReadonlyArray<PrivateClawThinkingEntry>,
376
+ ): PrivateClawThinkingEntry[] {
377
+ return entries.map(cloneThinkingEntry);
378
+ }
379
+
313
380
  function isAudioAttachment(attachment: PrivateClawAttachment): boolean {
314
381
  const normalizedMimeType = attachment.mimeType.trim().toLowerCase();
315
382
  if (normalizedMimeType.startsWith("audio/")) {
@@ -580,8 +647,25 @@ export class PrivateClawProvider {
580
647
  });
581
648
  }
582
649
 
650
+ private isVerboseLoggingEnabled(): boolean {
651
+ return this.options.verboseController?.enabled === true;
652
+ }
653
+
654
+ private verboseLog(message: string): void {
655
+ if (!this.isVerboseLoggingEnabled()) {
656
+ return;
657
+ }
658
+ this.options.onLog?.(`[provider][verbose] ${message}`);
659
+ }
660
+
583
661
  async connect(): Promise<void> {
662
+ this.verboseLog(
663
+ `connect_start providerId=${this.relayClient.getProviderId()} relay=${JSON.stringify(this.options.providerWsUrl)}`,
664
+ );
584
665
  await this.relayClient.connect();
666
+ this.verboseLog(
667
+ `connect_complete providerId=${this.relayClient.getProviderId()} activeSessions=${this.sessions.size}`,
668
+ );
585
669
  }
586
670
 
587
671
  async dispose(params?: { closeSessions?: boolean }): Promise<void> {
@@ -740,7 +824,9 @@ export class PrivateClawProvider {
740
824
  private buildBridgeHistory(
741
825
  session: ProviderSessionState,
742
826
  ): PrivateClawConversationTurn[] {
743
- return session.history.map(formatBridgeHistoryTurn);
827
+ return session.history
828
+ .filter((turn) => turn.role !== "thinking")
829
+ .map(formatBridgeHistoryTurn);
744
830
  }
745
831
 
746
832
  private async prepareUserMessage(
@@ -749,30 +835,80 @@ export class PrivateClawProvider {
749
835
  participant: ProviderParticipantState | undefined,
750
836
  ): Promise<PreparedUserMessage> {
751
837
  const allAttachments = payload.attachments ?? [];
838
+ const directBridgeSlashCommand = normalizeBridgeSlashCommandText(payload.text);
752
839
  const audioAttachments = allAttachments.filter(isAudioAttachment);
840
+ const providerAudioTranscriber = this.options.audioTranscriber;
841
+ const bridgeAudioTranscriber = this.options.bridge.transcribeAudioAttachments
842
+ ? {
843
+ transcribeAudioAttachments: this.options.bridge.transcribeAudioAttachments.bind(
844
+ this.options.bridge,
845
+ ),
846
+ }
847
+ : undefined;
848
+ const availableAudioTranscribers = [
849
+ ...(providerAudioTranscriber
850
+ ? [{ via: "provider" as const, transcriber: providerAudioTranscriber }]
851
+ : []),
852
+ ...(bridgeAudioTranscriber
853
+ ? [{ via: "bridge" as const, transcriber: bridgeAudioTranscriber }]
854
+ : []),
855
+ ];
753
856
  if (
754
857
  audioAttachments.length === 0 ||
755
- !this.options.bridge.transcribeAudioAttachments
858
+ availableAudioTranscribers.length === 0
756
859
  ) {
860
+ this.verboseLog(
861
+ `prepared_user_message session=${session.invite.sessionId} request=${payload.clientMessageId} voiceTranscribed=false textChars=${payload.text.length} attachments=${allAttachments.length} bridgeAttachments=${allAttachments.length}`,
862
+ );
757
863
  return {
758
864
  text: payload.text,
865
+ ...(directBridgeSlashCommand
866
+ ? {
867
+ bridgeText: directBridgeSlashCommand,
868
+ historyBridgeText: directBridgeSlashCommand,
869
+ }
870
+ : {}),
759
871
  ...(allAttachments.length > 0 ? { attachments: allAttachments } : {}),
760
872
  ...(allAttachments.length > 0 ? { bridgeAttachments: allAttachments } : {}),
761
873
  };
762
874
  }
763
875
 
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.");
876
+ let transcript = "";
877
+ let transcriptVia: "provider" | "bridge" | undefined;
878
+ const transcriptionFailures: string[] = [];
879
+ for (let index = 0; index < availableAudioTranscribers.length; index += 1) {
880
+ const candidate = availableAudioTranscribers[index]!;
881
+ const nextCandidate = availableAudioTranscribers[index + 1];
882
+ this.options.onLog?.(
883
+ `[provider] voice_transcription_start session=${session.invite.sessionId} request=${payload.clientMessageId} audioAttachments=${audioAttachments.length} via=${candidate.via}`,
884
+ );
885
+ try {
886
+ transcript = (
887
+ await candidate.transcriber.transcribeAudioAttachments({
888
+ sessionId: session.invite.sessionId,
889
+ requestId: payload.clientMessageId,
890
+ attachments: audioAttachments,
891
+ })
892
+ ).trim();
893
+ if (transcript === "") {
894
+ throw new Error("OpenClaw STT returned an empty transcript.");
895
+ }
896
+ transcriptVia = candidate.via;
897
+ break;
898
+ } catch (error) {
899
+ const detail = error instanceof Error ? error.message : String(error);
900
+ transcriptionFailures.push(`${candidate.via}: ${detail}`);
901
+ if (nextCandidate) {
902
+ this.options.onLog?.(
903
+ `[provider] voice_transcription_fallback session=${session.invite.sessionId} request=${payload.clientMessageId} from=${candidate.via} to=${nextCandidate.via} reason=${JSON.stringify(detail.slice(0, 300))}`,
904
+ );
905
+ }
906
+ }
907
+ }
908
+ if (!transcriptVia) {
909
+ throw new Error(
910
+ `OpenClaw STT failed for ${payload.clientMessageId}: ${transcriptionFailures.join(" | ")}`,
911
+ );
776
912
  }
777
913
 
778
914
  const text = mergeVoiceTranscriptText(transcript, payload.text);
@@ -784,7 +920,10 @@ export class PrivateClawProvider {
784
920
  (attachment) => !isAudioAttachment(attachment),
785
921
  );
786
922
  this.options.onLog?.(
787
- `[provider] voice_transcription_complete session=${session.invite.sessionId} request=${payload.clientMessageId} transcriptChars=${transcript.length} passthroughAttachments=${passthroughAttachments.length}`,
923
+ `[provider] voice_transcription_complete session=${session.invite.sessionId} request=${payload.clientMessageId} transcriptChars=${transcript.length} passthroughAttachments=${passthroughAttachments.length} via=${transcriptVia}`,
924
+ );
925
+ this.verboseLog(
926
+ `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
927
  );
789
928
  return {
790
929
  text: payload.text,
@@ -866,6 +1005,7 @@ export class PrivateClawProvider {
866
1005
  appId?: string;
867
1006
  deviceLabel?: string;
868
1007
  displayName?: string;
1008
+ supportsThinkingTrace?: boolean;
869
1009
  sentAt: string;
870
1010
  },
871
1011
  ): Promise<{ participant: ProviderParticipantState; isNew: boolean }> {
@@ -882,9 +1022,15 @@ export class PrivateClawProvider {
882
1022
  ...existing,
883
1023
  ...(params.deviceLabel ? { deviceLabel: params.deviceLabel } : {}),
884
1024
  ...(requestedDisplayName ? { displayName: requestedDisplayName } : {}),
1025
+ ...(typeof params.supportsThinkingTrace === "boolean"
1026
+ ? { supportsThinkingTrace: params.supportsThinkingTrace }
1027
+ : {}),
885
1028
  lastSeenAt: params.sentAt,
886
1029
  };
887
1030
  session.participants.set(normalizedAppId, participant);
1031
+ this.verboseLog(
1032
+ `participant_upsert session=${sessionId} appId=${JSON.stringify(normalizedAppId)} isNew=false displayName=${JSON.stringify(participant.displayName)} participants=${session.participants.size}`,
1033
+ );
888
1034
  return { participant, isNew: false };
889
1035
  }
890
1036
 
@@ -898,10 +1044,16 @@ export class PrivateClawProvider {
898
1044
  usedLabels,
899
1045
  ),
900
1046
  ...(params.deviceLabel ? { deviceLabel: params.deviceLabel } : {}),
1047
+ ...(typeof params.supportsThinkingTrace === "boolean"
1048
+ ? { supportsThinkingTrace: params.supportsThinkingTrace }
1049
+ : {}),
901
1050
  joinedAt: params.sentAt,
902
1051
  lastSeenAt: params.sentAt,
903
1052
  };
904
1053
  session.participants.set(normalizedAppId, participant);
1054
+ this.verboseLog(
1055
+ `participant_upsert session=${sessionId} appId=${JSON.stringify(normalizedAppId)} isNew=true displayName=${JSON.stringify(participant.displayName)} participants=${session.participants.size}`,
1056
+ );
905
1057
  return { participant, isNew: true };
906
1058
  }
907
1059
 
@@ -911,6 +1063,9 @@ export class PrivateClawProvider {
911
1063
  payload: Parameters<typeof encryptPayload>[0]["payload"],
912
1064
  targetAppId?: string,
913
1065
  ): Promise<void> {
1066
+ this.verboseLog(
1067
+ `payload_out session=${sessionId} ${summarizePayload(payload)} target=${JSON.stringify(targetAppId ?? "broadcast")}`,
1068
+ );
914
1069
  await this.relayClient.sendFrame(
915
1070
  sessionId,
916
1071
  encryptPayload({
@@ -973,6 +1128,57 @@ export class PrivateClawProvider {
973
1128
  }, params.targetAppId);
974
1129
  }
975
1130
 
1131
+ async sendThinkingMessage(
1132
+ sessionId: string,
1133
+ params: {
1134
+ messageId: string;
1135
+ status: PrivateClawThinkingStatus;
1136
+ summary: string;
1137
+ entries: ReadonlyArray<PrivateClawThinkingEntry>;
1138
+ replyTo?: string;
1139
+ sentAt?: string;
1140
+ targetAppId?: string;
1141
+ storeHistory?: boolean;
1142
+ },
1143
+ ): Promise<void> {
1144
+ const sentAt = params.sentAt ?? nowIso();
1145
+ const session = this.requireSession(sessionId);
1146
+ if (params.storeHistory !== false) {
1147
+ this.upsertThinkingHistoryTurn(session, {
1148
+ messageId: params.messageId,
1149
+ sentAt,
1150
+ status: params.status,
1151
+ summary: params.summary,
1152
+ entries: params.entries,
1153
+ ...(params.replyTo ? { replyTo: params.replyTo } : {}),
1154
+ });
1155
+ }
1156
+ const targetAppIds = params.targetAppId
1157
+ ? (session.participants.get(params.targetAppId)?.supportsThinkingTrace === true
1158
+ ? [params.targetAppId]
1159
+ : [])
1160
+ : [...session.participants.values()]
1161
+ .filter((participant) => participant.supportsThinkingTrace === true)
1162
+ .map((participant) => participant.appId);
1163
+ if (targetAppIds.length === 0) {
1164
+ return;
1165
+ }
1166
+ const payload = {
1167
+ kind: "thinking_message",
1168
+ messageId: params.messageId,
1169
+ status: params.status,
1170
+ summary: params.summary,
1171
+ entries: cloneThinkingEntries(params.entries),
1172
+ sentAt,
1173
+ ...(params.replyTo ? { replyTo: params.replyTo } : {}),
1174
+ } as const;
1175
+ await Promise.all(
1176
+ targetAppIds.map((targetAppId) =>
1177
+ this.sendPayload(sessionId, payload, targetAppId),
1178
+ ),
1179
+ );
1180
+ }
1181
+
976
1182
  private async sendPendingAssistantStatus(
977
1183
  sessionId: string,
978
1184
  params: {
@@ -1190,6 +1396,37 @@ export class PrivateClawProvider {
1190
1396
  });
1191
1397
  }
1192
1398
 
1399
+ private upsertThinkingHistoryTurn(
1400
+ session: ProviderSessionState,
1401
+ params: {
1402
+ messageId: string;
1403
+ replyTo?: string;
1404
+ sentAt: string;
1405
+ status: PrivateClawThinkingStatus;
1406
+ summary: string;
1407
+ entries: ReadonlyArray<PrivateClawThinkingEntry>;
1408
+ },
1409
+ ): void {
1410
+ const turn: PrivateClawConversationTurn = {
1411
+ messageId: params.messageId,
1412
+ role: "thinking",
1413
+ text: params.summary,
1414
+ sentAt: params.sentAt,
1415
+ thinkingStatus: params.status,
1416
+ thinkingSummary: params.summary,
1417
+ thinkingEntries: cloneThinkingEntries(params.entries),
1418
+ ...(params.replyTo ? { replyTo: params.replyTo } : {}),
1419
+ };
1420
+ const existingIndex = session.history.findIndex(
1421
+ (item) => item.messageId === params.messageId,
1422
+ );
1423
+ if (existingIndex >= 0) {
1424
+ session.history[existingIndex] = turn;
1425
+ return;
1426
+ }
1427
+ session.history.push(turn);
1428
+ }
1429
+
1193
1430
  private updateStoredUserBridgeText(
1194
1431
  session: ProviderSessionState,
1195
1432
  messageId: string,
@@ -1262,13 +1499,17 @@ export class PrivateClawProvider {
1262
1499
  const currentParticipant = params?.targetAppId
1263
1500
  ? session.participants.get(params.targetAppId)
1264
1501
  : undefined;
1502
+ const commands = await this.listAvailableCommands(session);
1503
+ this.verboseLog(
1504
+ `capabilities_out session=${sessionId} targetAppId=${JSON.stringify(params?.targetAppId ?? "broadcast")} includeCurrentIdentity=${params?.includeCurrentIdentity === true} commands=${commands.length} participants=${session.participants.size} groupMode=${session.groupMode}`,
1505
+ );
1265
1506
  await this.sendPayload(sessionId, {
1266
1507
  kind: "provider_capabilities",
1267
1508
  sentAt: nowIso(),
1268
1509
  expiresAt: session.invite.expiresAt,
1269
1510
  ...(session.groupMode ? { groupMode: true } : {}),
1270
1511
  ...(session.groupMode ? { botMuted: session.botMuted } : {}),
1271
- commands: await this.listAvailableCommands(session),
1512
+ commands,
1272
1513
  ...(session.groupMode
1273
1514
  ? { participants: this.listParticipants(session) }
1274
1515
  : {}),
@@ -1289,6 +1530,9 @@ export class PrivateClawProvider {
1289
1530
  targetAppId: string,
1290
1531
  ): Promise<void> {
1291
1532
  const session = this.requireSession(sessionId);
1533
+ this.verboseLog(
1534
+ `history_snapshot_out session=${sessionId} targetAppId=${JSON.stringify(targetAppId)} turns=${session.history.length}`,
1535
+ );
1292
1536
  for (const turn of session.history) {
1293
1537
  switch (turn.role) {
1294
1538
  case "assistant":
@@ -1316,6 +1560,18 @@ export class PrivateClawProvider {
1316
1560
  },
1317
1561
  );
1318
1562
  break;
1563
+ case "thinking":
1564
+ await this.sendThinkingMessage(sessionId, {
1565
+ messageId: turn.messageId,
1566
+ status: turn.thinkingStatus ?? "completed",
1567
+ summary: turn.thinkingSummary ?? turn.text,
1568
+ entries: turn.thinkingEntries ?? [],
1569
+ sentAt: turn.sentAt,
1570
+ targetAppId,
1571
+ storeHistory: false,
1572
+ ...(turn.replyTo ? { replyTo: turn.replyTo } : {}),
1573
+ });
1574
+ break;
1319
1575
  case "user":
1320
1576
  if (!session.groupMode || !turn.appId || !turn.participantLabel) {
1321
1577
  break;
@@ -1391,6 +1647,10 @@ export class PrivateClawProvider {
1391
1647
  sessionKey: session.invite.sessionKey,
1392
1648
  envelope,
1393
1649
  });
1650
+ const payloadRecord = toUnknownRecord(payload);
1651
+ this.verboseLog(
1652
+ `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)}`,
1653
+ );
1394
1654
 
1395
1655
  switch (payload.kind) {
1396
1656
  case "client_hello": {
@@ -1405,6 +1665,7 @@ export class PrivateClawProvider {
1405
1665
  }
1406
1666
  const participantState = await this.upsertParticipant(sessionId, {
1407
1667
  sentAt: payload.sentAt,
1668
+ supportsThinkingTrace: payload.supportsThinkingTrace === true,
1408
1669
  ...(payload.appId ? { appId: normalizedAppId } : {}),
1409
1670
  ...(payload.deviceLabel
1410
1671
  ? { deviceLabel: payload.deviceLabel }
@@ -1416,6 +1677,9 @@ export class PrivateClawProvider {
1416
1677
  const participant = participantState.participant;
1417
1678
  const wasAwaitingHello = session.state !== "active";
1418
1679
  const wasRenewing = Boolean(session.pendingRenewal);
1680
+ this.verboseLog(
1681
+ `client_hello_processed session=${sessionId} appId=${JSON.stringify(participant.appId)} isNew=${participantState.isNew} participants=${session.participants.size} awaitingHello=${wasAwaitingHello} renewing=${wasRenewing} groupMode=${session.groupMode}`,
1682
+ );
1419
1683
  session.state = "active";
1420
1684
  if (wasRenewing) {
1421
1685
  session.history.push({
@@ -1495,6 +1759,7 @@ export class PrivateClawProvider {
1495
1759
  : undefined);
1496
1760
 
1497
1761
  const normalizedCommand = payload.text.trim().toLowerCase();
1762
+ const directBridgeSlashCommand = normalizeBridgeSlashCommandText(payload.text);
1498
1763
  const isRenewCommand =
1499
1764
  normalizedCommand === "/renew-session" ||
1500
1765
  normalizedCommand === "/session_renew";
@@ -1747,7 +2012,7 @@ export class PrivateClawProvider {
1747
2012
  }
1748
2013
  }
1749
2014
 
1750
- if (session.groupMode && session.botMuted) {
2015
+ if (session.groupMode && session.botMuted && !directBridgeSlashCommand) {
1751
2016
  if (!shouldHandleVoiceAsynchronously) {
1752
2017
  await this.sendParticipantMessage(sessionId, {
1753
2018
  text: payload.text,
@@ -1832,12 +2097,28 @@ export class PrivateClawProvider {
1832
2097
  });
1833
2098
  }
1834
2099
 
2100
+ const bridgeMessage =
2101
+ preparedMessage.bridgeText ??
2102
+ (session.groupMode && participant
2103
+ ? `${participant.displayName}: ${preparedMessage.text}`
2104
+ : preparedMessage.text);
2105
+ const supportsThinkingTrace =
2106
+ this.options.bridge.supportsThinkingTrace === true;
2107
+ const thinkingMessageId = buildThinkingMessageId(payload.clientMessageId);
2108
+ let latestThinkingSummary = "";
2109
+ let latestThinkingEntries: PrivateClawThinkingEntry[] = [];
1835
2110
  try {
1836
- const bridgeMessage =
1837
- preparedMessage.bridgeText ??
1838
- (session.groupMode && participant
1839
- ? `${participant.displayName}: ${preparedMessage.text}`
1840
- : preparedMessage.text);
2111
+ if (supportsThinkingTrace) {
2112
+ await this.sendThinkingMessage(sessionId, {
2113
+ messageId: thinkingMessageId,
2114
+ status: "started",
2115
+ summary: "",
2116
+ entries: [],
2117
+ replyTo: payload.clientMessageId,
2118
+ sentAt: payload.sentAt,
2119
+ storeHistory: false,
2120
+ });
2121
+ }
1841
2122
  const bridgeResponse = await this.options.bridge.handleUserMessage({
1842
2123
  sessionId,
1843
2124
  invite: session.invite,
@@ -1846,9 +2127,36 @@ export class PrivateClawProvider {
1846
2127
  ? { attachments: preparedMessage.bridgeAttachments }
1847
2128
  : preparedMessage.attachments
1848
2129
  ? { attachments: preparedMessage.attachments }
1849
- : {}),
2130
+ : {}),
1850
2131
  history: this.buildBridgeHistory(session),
2132
+ ...(supportsThinkingTrace
2133
+ ? {
2134
+ onThinkingTrace: async (snapshot) => {
2135
+ latestThinkingSummary = snapshot.summary;
2136
+ latestThinkingEntries = cloneThinkingEntries(snapshot.entries);
2137
+ await this.sendThinkingMessage(sessionId, {
2138
+ messageId: thinkingMessageId,
2139
+ status: "streaming",
2140
+ summary: snapshot.summary,
2141
+ entries: snapshot.entries,
2142
+ replyTo: payload.clientMessageId,
2143
+ sentAt: snapshot.sentAt,
2144
+ storeHistory: snapshot.entries.length > 0,
2145
+ });
2146
+ },
2147
+ }
2148
+ : {}),
1851
2149
  });
2150
+ if (supportsThinkingTrace) {
2151
+ await this.sendThinkingMessage(sessionId, {
2152
+ messageId: thinkingMessageId,
2153
+ status: "completed",
2154
+ summary: latestThinkingSummary,
2155
+ entries: latestThinkingEntries,
2156
+ replyTo: payload.clientMessageId,
2157
+ storeHistory: latestThinkingEntries.length > 0,
2158
+ });
2159
+ }
1852
2160
 
1853
2161
  for (const message of normalizeBridgeMessages(bridgeResponse)) {
1854
2162
  this.options.onLog?.(
@@ -1866,6 +2174,16 @@ export class PrivateClawProvider {
1866
2174
  });
1867
2175
  }
1868
2176
  } catch (error) {
2177
+ if (supportsThinkingTrace) {
2178
+ await this.sendThinkingMessage(sessionId, {
2179
+ messageId: thinkingMessageId,
2180
+ status: "failed",
2181
+ summary: latestThinkingSummary,
2182
+ entries: latestThinkingEntries,
2183
+ replyTo: payload.clientMessageId,
2184
+ storeHistory: latestThinkingEntries.length > 0,
2185
+ });
2186
+ }
1869
2187
  await this.sendSystemMessage(
1870
2188
  sessionId,
1871
2189
  buildBridgeErrorMessage(
@@ -1963,6 +2281,9 @@ export class PrivateClawProvider {
1963
2281
  state: "awaiting_hello",
1964
2282
  });
1965
2283
  this.scheduleRenewalReminder(sessionId);
2284
+ this.verboseLog(
2285
+ `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}`,
2286
+ );
1966
2287
  return this.buildInviteBundleForInvite(invite);
1967
2288
  }
1968
2289