@@ -147,7 +147,42 @@ export class Logger {
147147 return result
148148 }
149149
150- async saveWrappedContext ( sessionID : string , messages : any [ ] , metadata : any ) {
150+ private extractReasoningBlocks ( sessionMessages : any [ ] ) : any [ ] {
151+ const reasoningBlocks : any [ ] = [ ]
152+
153+ for ( const msg of sessionMessages ) {
154+ if ( ! msg . parts ) continue
155+
156+ for ( const part of msg . parts ) {
157+ if ( part . type === "reasoning" ) {
158+ // Calculate encrypted content size for different providers
159+ let encryptedContentLength = 0
160+ if ( part . metadata ?. openai ?. reasoningEncryptedContent ) {
161+ encryptedContentLength = part . metadata . openai . reasoningEncryptedContent . length
162+ } else if ( part . metadata ?. anthropic ?. signature ) {
163+ encryptedContentLength = part . metadata . anthropic . signature . length
164+ } else if ( part . metadata ?. google ?. thoughtSignature ) {
165+ encryptedContentLength = part . metadata . google . thoughtSignature . length
166+ }
167+
168+ reasoningBlocks . push ( {
169+ messageId : msg . id ,
170+ messageRole : msg . role ,
171+ text : part . text ,
172+ textLength : part . text ?. length || 0 ,
173+ encryptedContentLength,
174+ time : part . time ,
175+ hasMetadata : ! ! part . metadata ,
176+ metadataKeys : part . metadata ? Object . keys ( part . metadata ) : [ ]
177+ } )
178+ }
179+ }
180+ }
181+
182+ return reasoningBlocks
183+ }
184+
185+ async saveWrappedContext ( sessionID : string , messages : any [ ] , metadata : any , sessionMessages ?: any [ ] ) {
151186 if ( ! this . enabled ) return
152187
153188 try {
@@ -197,11 +232,24 @@ export class Logger {
197232 }
198233 }
199234 } else {
235+ // Extract reasoning blocks from session messages if available
236+ const reasoningBlocks = sessionMessages
237+ ? this . extractReasoningBlocks ( sessionMessages )
238+ : [ ]
239+
200240 content = {
201241 timestamp : new Date ( ) . toISOString ( ) ,
202242 sessionID,
203243 metadata,
204- messages
244+ messages,
245+ ...( reasoningBlocks . length > 0 && {
246+ reasoning : {
247+ count : reasoningBlocks . length ,
248+ totalTextCharacters : reasoningBlocks . reduce ( ( sum , b ) => sum + b . textLength , 0 ) ,
249+ totalEncryptedCharacters : reasoningBlocks . reduce ( ( sum , b ) => sum + b . encryptedContentLength , 0 ) ,
250+ blocks : reasoningBlocks
251+ }
252+ } )
205253 }
206254 }
207255
0 commit comments