@@ -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,33 +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
101- async forgetMemory ( containerTag : string , memoryId ?: string ) {
105+ async deleteMemory ( memoryId : string ) {
106+ log ( "deleteMemory: start" , { memoryId } ) ;
102107 try {
103- return await withTimeout (
104- this . getClient ( ) . memories . forget ( {
105- containerTag,
106- id : memoryId ,
107- } ) ,
108+ await withTimeout (
109+ this . getClient ( ) . memories . delete ( memoryId ) ,
108110 TIMEOUT_MS
109111 ) ;
112+ log ( "deleteMemory: success" , { memoryId } ) ;
113+ return { success : true } ;
110114 } catch ( error ) {
111- console . error ( "Supermemory: forget memory failed" , error ) ;
112- 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 } ;
113118 }
114119 }
115120
@@ -126,11 +131,11 @@ export class SupermemoryClient {
126131 TIMEOUT_MS
127132 ) ;
128133 log ( "listMemories: success" , { count : result . memories ?. length || 0 } ) ;
129- return result ;
134+ return { success : true as const , ... result } ;
130135 } catch ( error ) {
131- log ( "listMemories: error" , { error : String ( error ) } ) ;
132- console . error ( "Supermemory: list memories failed ", error ) ;
133- 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 } } ;
134139 }
135140 }
136141
@@ -139,7 +144,7 @@ export class SupermemoryClient {
139144 messages : ConversationMessage [ ] ,
140145 containerTags : string [ ] ,
141146 metadata ?: Record < string , string | number | boolean >
142- ) : Promise < ConversationIngestResponse | null > {
147+ ) {
143148 log ( "ingestConversation: start" , { conversationId, messageCount : messages . length } ) ;
144149 try {
145150 const response = await withTimeout (
@@ -162,16 +167,16 @@ export class SupermemoryClient {
162167 if ( ! response . ok ) {
163168 const errorText = await response . text ( ) ;
164169 log ( "ingestConversation: error response" , { status : response . status , error : errorText } ) ;
165- return null ;
170+ return { success : false as const , error : `HTTP ${ response . status } : ${ errorText } ` } ;
166171 }
167172
168173 const result = await response . json ( ) as ConversationIngestResponse ;
169174 log ( "ingestConversation: success" , { conversationId, status : result . status } ) ;
170- return result ;
175+ return { success : true as const , ... result } ;
171176 } catch ( error ) {
172- log ( "ingestConversation: error" , { error : String ( error ) } ) ;
173- console . error ( "Supermemory: ingest conversation failed ", error ) ;
174- 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 } ;
175180 }
176181 }
177182}
0 commit comments