@@ -51,11 +51,11 @@ export class SupermemoryClient {
5151 TIMEOUT_MS
5252 ) ;
5353 log ( "searchMemories: success" , { count : result . results ?. length || 0 } ) ;
54- return result ;
54+ return { success : true as const , ... result } ;
5555 } catch ( error ) {
56- log ( "searchMemories: error" , { error : String ( error ) } ) ;
57- console . error ( "Supermemory: search failed ", error ) ;
58- return { results : [ ] , total : 0 , timing : 0 } ;
56+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
57+ log ( "searchMemories: error ", { error : errorMessage } ) ;
58+ return { success : false as const , error : errorMessage , results : [ ] , total : 0 , timing : 0 } ;
5959 }
6060 }
6161
@@ -70,11 +70,11 @@ export class SupermemoryClient {
7070 TIMEOUT_MS
7171 ) ;
7272 log ( "getProfile: success" , { hasProfile : ! ! result ?. profile } ) ;
73- return result ;
73+ return { success : true as const , ... result } ;
7474 } catch ( error ) {
75- log ( "getProfile: error" , { error : String ( error ) } ) ;
76- console . error ( "Supermemory: profile fetch failed ", error ) ;
77- return null ;
75+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
76+ log ( "getProfile: error ", { error : errorMessage } ) ;
77+ return { success : false as const , error : errorMessage , profile : null } ;
7878 }
7979 }
8080
@@ -83,31 +83,38 @@ export class SupermemoryClient {
8383 containerTag : string ,
8484 metadata ?: { type ?: MemoryType ; tool ?: string ; [ key : string ] : unknown }
8585 ) {
86+ log ( "addMemory: start" , { containerTag, contentLength : content . length } ) ;
8687 try {
87- return await withTimeout (
88+ const result = await withTimeout (
8889 this . getClient ( ) . memories . add ( {
8990 content,
9091 containerTag,
9192 metadata : metadata as Record < string , string | number | boolean | string [ ] > ,
9293 } ) ,
9394 TIMEOUT_MS
9495 ) ;
96+ log ( "addMemory: success" , { id : result . id } ) ;
97+ return { success : true as const , ...result } ;
9598 } catch ( error ) {
96- console . error ( "Supermemory: add memory failed" , error ) ;
97- return null ;
99+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
100+ log ( "addMemory: error" , { error : errorMessage } ) ;
101+ return { success : false as const , error : errorMessage } ;
98102 }
99103 }
100104
101105 async deleteMemory ( memoryId : string ) {
106+ log ( "deleteMemory: start" , { memoryId } ) ;
102107 try {
103108 await withTimeout (
104109 this . getClient ( ) . memories . delete ( memoryId ) ,
105110 TIMEOUT_MS
106111 ) ;
112+ log ( "deleteMemory: success" , { memoryId } ) ;
107113 return { success : true } ;
108114 } catch ( error ) {
109- console . error ( "Supermemory: delete memory failed" , error ) ;
110- return null ;
115+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
116+ log ( "deleteMemory: error" , { memoryId, error : errorMessage } ) ;
117+ return { success : false , error : errorMessage } ;
111118 }
112119 }
113120
@@ -124,11 +131,11 @@ export class SupermemoryClient {
124131 TIMEOUT_MS
125132 ) ;
126133 log ( "listMemories: success" , { count : result . memories ?. length || 0 } ) ;
127- return result ;
134+ return { success : true as const , ... result } ;
128135 } catch ( error ) {
129- log ( "listMemories: error" , { error : String ( error ) } ) ;
130- console . error ( "Supermemory: list memories failed ", error ) ;
131- return { memories : [ ] , pagination : { currentPage : 1 , totalItems : 0 , totalPages : 0 } } ;
136+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
137+ log ( "listMemories: error ", { error : errorMessage } ) ;
138+ return { success : false as const , error : errorMessage , memories : [ ] , pagination : { currentPage : 1 , totalItems : 0 , totalPages : 0 } } ;
132139 }
133140 }
134141
@@ -137,7 +144,7 @@ export class SupermemoryClient {
137144 messages : ConversationMessage [ ] ,
138145 containerTags : string [ ] ,
139146 metadata ?: Record < string , string | number | boolean >
140- ) : Promise < ConversationIngestResponse | null > {
147+ ) {
141148 log ( "ingestConversation: start" , { conversationId, messageCount : messages . length } ) ;
142149 try {
143150 const response = await withTimeout (
@@ -160,16 +167,16 @@ export class SupermemoryClient {
160167 if ( ! response . ok ) {
161168 const errorText = await response . text ( ) ;
162169 log ( "ingestConversation: error response" , { status : response . status , error : errorText } ) ;
163- return null ;
170+ return { success : false as const , error : `HTTP ${ response . status } : ${ errorText } ` } ;
164171 }
165172
166173 const result = await response . json ( ) as ConversationIngestResponse ;
167174 log ( "ingestConversation: success" , { conversationId, status : result . status } ) ;
168- return result ;
175+ return { success : true as const , ... result } ;
169176 } catch ( error ) {
170- log ( "ingestConversation: error" , { error : String ( error ) } ) ;
171- console . error ( "Supermemory: ingest conversation failed ", error ) ;
172- return null ;
177+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
178+ log ( "ingestConversation: error ", { error : errorMessage } ) ;
179+ return { success : false as const , error : errorMessage } ;
173180 }
174181 }
175182}
0 commit comments