@@ -47,7 +47,12 @@ export class SupermemoryClient {
4747 log . warn ( `container tag warning: ${ tagCheck . reason } ` )
4848 }
4949
50- this . client = new Supermemory ( { apiKey } )
50+ // `x-sm-source` is read by mono's API to attribute searches and
51+ // writes to the OpenClaw plugin in PostHog / `document.source`.
52+ this . client = new Supermemory ( {
53+ apiKey,
54+ defaultHeaders : { "x-sm-source" : "openclaw" } ,
55+ } )
5156 this . containerTag = containerTag
5257 log . info ( `initialized (container: ${ containerTag } )` )
5358 }
@@ -58,14 +63,23 @@ export class SupermemoryClient {
5863 customId ?: string ,
5964 containerTag ?: string ,
6065 entityContext ?: string ,
61- ) : Promise < { id : string } > {
66+ ) : Promise < { id : string ; status : string } > {
6267 const cleaned = sanitizeContent ( content )
6368 const tag = containerTag ?? this . containerTag
6469
70+ // Always stamp `sm_source` so mono's `document.source` column attributes
71+ // these writes to the OpenClaw plugin. Existing callers can still pass
72+ // extra metadata (e.g. `source: "openclaw_tool"`) and it is preserved
73+ // underneath the canonical `sm_source` key.
74+ const mergedMetadata : Record < string , string | number | boolean > = {
75+ sm_source : "openclaw" ,
76+ ...( metadata ?? { } ) ,
77+ }
78+
6579 log . debugRequest ( "add" , {
6680 contentLength : cleaned . length ,
6781 customId,
68- metadata,
82+ metadata : mergedMetadata ,
6983 containerTag : tag ,
7084 } )
7185
@@ -76,13 +90,22 @@ export class SupermemoryClient {
7690 const result = await this . client . add ( {
7791 content : cleaned ,
7892 containerTag : tag ,
79- ... ( metadata && { metadata } ) ,
93+ metadata : mergedMetadata ,
8094 ...( customId && { customId } ) ,
8195 ...( clampedCtx && { entityContext : clampedCtx } ) ,
8296 } )
8397
84- log . debugResponse ( "add" , { id : result . id } )
85- return { id : result . id }
98+ log . debugResponse ( "add" , { id : result . id , status : result . status } )
99+
100+ if ( result . status === "failed" ) {
101+ log . warn (
102+ `add returned status="failed" for id=${ result . id } ` +
103+ ( customId ? ` customId=${ customId } ` : "" ) +
104+ ` (contentLength=${ cleaned . length } , containerTag=${ tag } )` ,
105+ )
106+ }
107+
108+ return { id : result . id , status : result . status }
86109 }
87110
88111 async search (
0 commit comments