@@ -2,7 +2,7 @@ import type { ProfileResponse } from "supermemory/resources";
22import { CONFIG } from "../config.js" ;
33
44interface MemoryResultMinimal {
5- similarity : number ;
5+ similarity ? : number ;
66 memory ?: string ;
77 chunk ?: string ;
88}
@@ -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,14 +34,16 @@ export function formatContextForPrompt(
2434 if ( staticFacts . length > 0 ) {
2535 parts . push ( "\nUser Profile:" ) ;
2636 staticFacts . slice ( 0 , CONFIG . maxProfileItems ) . forEach ( ( fact ) => {
27- parts . push ( `- ${ fact } ` ) ;
37+ const text = extractFactText ( fact ) ;
38+ parts . push ( `- ${ text } ` ) ;
2839 } ) ;
2940 }
3041
3142 if ( dynamicFacts . length > 0 ) {
3243 parts . push ( "\nRecent Context:" ) ;
3344 dynamicFacts . slice ( 0 , CONFIG . maxProfileItems ) . forEach ( ( fact ) => {
34- parts . push ( `- ${ fact } ` ) ;
45+ const text = extractFactText ( fact ) ;
46+ parts . push ( `- ${ text } ` ) ;
3547 } ) ;
3648 }
3749 }
@@ -40,7 +52,7 @@ export function formatContextForPrompt(
4052 if ( projectResults . length > 0 ) {
4153 parts . push ( "\nProject Knowledge:" ) ;
4254 projectResults . forEach ( ( mem ) => {
43- const similarity = Math . round ( mem . similarity * 100 ) ;
55+ const similarity = Math . round ( ( mem . similarity ?? 0 ) * 100 ) ;
4456 const content = mem . memory || mem . chunk || "" ;
4557 parts . push ( `- [${ similarity } %] ${ content } ` ) ;
4658 } ) ;
@@ -50,7 +62,7 @@ export function formatContextForPrompt(
5062 if ( userResults . length > 0 ) {
5163 parts . push ( "\nRelevant Memories:" ) ;
5264 userResults . forEach ( ( mem ) => {
53- const similarity = Math . round ( mem . similarity * 100 ) ;
65+ const similarity = Math . round ( ( mem . similarity ?? 0 ) * 100 ) ;
5466 const content = mem . memory || mem . chunk || "" ;
5567 parts . push ( `- [${ similarity } %] ${ content } ` ) ;
5668 } ) ;
0 commit comments