@@ -11,6 +11,16 @@ interface MemoriesResponseMinimal {
1111 results ?: MemoryResultMinimal [ ] ;
1212}
1313
14+ function extractFactText ( fact : unknown ) : string {
15+ if ( typeof fact === "string" ) return fact ;
16+ if ( fact != null && typeof fact === "object" ) {
17+ const content = ( fact as { content ?: string } ) . content ;
18+ if ( typeof content === "string" ) return content ;
19+ return JSON . stringify ( fact ) ;
20+ }
21+ return String ( fact ?? "" ) ;
22+ }
23+
1424export function formatContextForPrompt (
1525 profile : ProfileResponse | null ,
1626 userMemories : MemoriesResponseMinimal ,
@@ -24,15 +34,15 @@ export function formatContextForPrompt(
2434 if ( staticFacts . length > 0 ) {
2535 parts . push ( "\nUser Profile:" ) ;
2636 staticFacts . slice ( 0 , CONFIG . maxProfileItems ) . forEach ( ( fact ) => {
27- const text = typeof fact === "string" ? fact : ( fact as { content ?: string } ) . content ?? String ( fact ) ;
37+ const text = extractFactText ( fact ) ;
2838 parts . push ( `- ${ text } ` ) ;
2939 } ) ;
3040 }
3141
3242 if ( dynamicFacts . length > 0 ) {
3343 parts . push ( "\nRecent Context:" ) ;
3444 dynamicFacts . slice ( 0 , CONFIG . maxProfileItems ) . forEach ( ( fact ) => {
35- const text = typeof fact === "string" ? fact : ( fact as { content ?: string } ) . content ?? String ( fact ) ;
45+ const text = extractFactText ( fact ) ;
3646 parts . push ( `- ${ text } ` ) ;
3747 } ) ;
3848 }
0 commit comments