11import { toError } from '@sim/utils/errors'
22import { Mem0Icon } from '@/components/icons'
33import { AuthMode , type BlockConfig , IntegrationType } from '@/blocks/types'
4- import type { Mem0Message , Mem0Response } from '@/tools/mem0/types'
5-
6- function isMem0Message ( value : unknown ) : value is Mem0Message {
7- return (
8- Boolean ( value ) &&
9- typeof value === 'object' &&
10- 'role' in value &&
11- 'content' in value &&
12- ( value . role === 'user' || value . role === 'assistant' ) &&
13- typeof value . content === 'string' &&
14- value . content . length > 0
15- )
16- }
17-
18- function parseMem0Messages ( value : unknown ) : Mem0Message [ ] {
19- if ( ! value ) {
20- throw new Error ( 'Messages are required for add operation' )
21- }
22-
23- let messages : unknown
24- try {
25- messages = typeof value === 'string' ? JSON . parse ( value ) : value
26- } catch ( error ) {
27- throw new Error ( `Messages must be valid JSON: ${ toError ( error ) . message } ` )
28- }
29-
30- if ( ! Array . isArray ( messages ) || messages . length === 0 ) {
31- throw new Error ( 'Messages must be a non-empty array' )
32- }
33-
34- const validMessages : Mem0Message [ ] = [ ]
35- for ( const message of messages ) {
36- if ( ! isMem0Message ( message ) ) {
37- throw new Error ( 'Each message must have role user or assistant and non-empty content' )
38- }
39- validMessages . push ( message )
40- }
41-
42- return validMessages
43- }
4+ import type { Mem0Response } from '@/tools/mem0/types'
5+ import { parseMem0Messages } from '@/tools/mem0/utils'
446
457export const Mem0Block : BlockConfig < Mem0Response > = {
468 type : 'mem0' ,
@@ -163,6 +125,17 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
163125 password : true ,
164126 required : true ,
165127 } ,
128+ {
129+ id : 'page' ,
130+ title : 'Page' ,
131+ type : 'short-input' ,
132+ placeholder : '1' ,
133+ condition : {
134+ field : 'operation' ,
135+ value : 'get' ,
136+ } ,
137+ mode : 'advanced' ,
138+ } ,
166139 {
167140 id : 'limit' ,
168141 title : 'Result Limit' ,
@@ -228,7 +201,7 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
228201
229202 if ( params . userId ) result . userId = params . userId
230203
231- if ( params . limit ) result . limit = params . limit
204+ if ( params . limit ) result . limit = Number ( params . limit )
232205
233206 switch ( operation ) {
234207 case 'add' :
@@ -260,6 +233,10 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
260233 result . memoryId = params . memoryId
261234 }
262235
236+ if ( params . page ) {
237+ result . page = Number ( params . page )
238+ }
239+
263240 if ( params . startDate ) {
264241 result . startDate = params . startDate
265242 }
@@ -283,6 +260,7 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
283260 memoryId : { type : 'string' , description : 'Memory identifier' } ,
284261 startDate : { type : 'string' , description : 'Start date filter' } ,
285262 endDate : { type : 'string' , description : 'End date filter' } ,
263+ page : { type : 'number' , description : 'Page number for paginated get results' } ,
286264 limit : { type : 'number' , description : 'Result limit' } ,
287265 } ,
288266 outputs : {
0 commit comments