@stackflo-labs/n8n-nodes-retainr 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,883 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Retainr = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ class Retainr {
6
+ constructor() {
7
+ this.description = {
8
+ displayName: 'Retainr',
9
+ name: 'retainr',
10
+ icon: 'file:retainr.svg',
11
+ group: ['transform'],
12
+ version: 1,
13
+ subtitle: '={{$parameter["operation"] + " " + $parameter["resource"]}}',
14
+ description: 'Store, search, and retrieve AI agent memories',
15
+ defaults: {
16
+ name: 'Retainr',
17
+ },
18
+ inputs: ['main'],
19
+ outputs: ['main'],
20
+ usableAsTool: true,
21
+ credentials: [
22
+ {
23
+ name: 'retainrApi',
24
+ required: true,
25
+ },
26
+ ],
27
+ properties: [
28
+ // ------------------------------------------------------------------
29
+ // Resource
30
+ // ------------------------------------------------------------------
31
+ {
32
+ displayName: 'Resource',
33
+ name: 'resource',
34
+ type: 'options',
35
+ noDataExpression: true,
36
+ options: [
37
+ {
38
+ name: 'Memory',
39
+ value: 'memory',
40
+ },
41
+ {
42
+ name: 'Workspace',
43
+ value: 'workspace',
44
+ },
45
+ ],
46
+ default: 'memory',
47
+ },
48
+ // ------------------------------------------------------------------
49
+ // Operations — Memory
50
+ // ------------------------------------------------------------------
51
+ {
52
+ displayName: 'Operation',
53
+ name: 'operation',
54
+ type: 'options',
55
+ noDataExpression: true,
56
+ displayOptions: {
57
+ show: {
58
+ resource: ['memory'],
59
+ },
60
+ },
61
+ options: [
62
+ {
63
+ name: 'Delete',
64
+ value: 'delete',
65
+ description: 'Delete memories matching a filter',
66
+ action: 'Delete memories',
67
+ },
68
+ {
69
+ name: 'Get Context',
70
+ value: 'getContext',
71
+ description: 'Get pre-formatted memory context for LLM prompts',
72
+ action: 'Get memory context',
73
+ },
74
+ {
75
+ name: 'List',
76
+ value: 'list',
77
+ description: 'List memories with optional filters',
78
+ action: 'List memories',
79
+ },
80
+ {
81
+ name: 'Search',
82
+ value: 'search',
83
+ description: 'Semantic search across memories',
84
+ action: 'Search memories',
85
+ },
86
+ {
87
+ name: 'Store',
88
+ value: 'store',
89
+ description: 'Store a new memory',
90
+ action: 'Store a memory',
91
+ },
92
+ ],
93
+ default: 'store',
94
+ },
95
+ // ------------------------------------------------------------------
96
+ // Operations — Workspace
97
+ // ------------------------------------------------------------------
98
+ {
99
+ displayName: 'Operation',
100
+ name: 'operation',
101
+ type: 'options',
102
+ noDataExpression: true,
103
+ displayOptions: {
104
+ show: {
105
+ resource: ['workspace'],
106
+ },
107
+ },
108
+ options: [
109
+ {
110
+ name: 'Get Info',
111
+ value: 'getInfo',
112
+ description: 'Get workspace details, usage, and API keys',
113
+ action: 'Get workspace info',
114
+ },
115
+ ],
116
+ default: 'getInfo',
117
+ },
118
+ // ==================================================================
119
+ // Fields — Memory > Store
120
+ // ==================================================================
121
+ {
122
+ displayName: 'Content',
123
+ name: 'content',
124
+ type: 'string',
125
+ typeOptions: {
126
+ rows: 4,
127
+ },
128
+ required: true,
129
+ default: '',
130
+ placeholder: 'The user prefers dark mode and speaks French.',
131
+ description: 'The memory content to store (max 32 768 characters)',
132
+ displayOptions: {
133
+ show: {
134
+ resource: ['memory'],
135
+ operation: ['store'],
136
+ },
137
+ },
138
+ },
139
+ {
140
+ displayName: 'Scope',
141
+ name: 'scope',
142
+ type: 'options',
143
+ required: true,
144
+ default: 'user',
145
+ description: 'Memory visibility scope',
146
+ options: [
147
+ {
148
+ name: 'Session',
149
+ value: 'session',
150
+ description: 'Scoped to a single workflow run',
151
+ },
152
+ {
153
+ name: 'User',
154
+ value: 'user',
155
+ description: 'Persists across runs for one user',
156
+ },
157
+ {
158
+ name: 'Agent',
159
+ value: 'agent',
160
+ description: 'Shared across users for one agent',
161
+ },
162
+ {
163
+ name: 'Global',
164
+ value: 'global',
165
+ description: 'Shared across the entire workspace',
166
+ },
167
+ ],
168
+ displayOptions: {
169
+ show: {
170
+ resource: ['memory'],
171
+ operation: ['store'],
172
+ },
173
+ },
174
+ },
175
+ {
176
+ displayName: 'Session ID',
177
+ name: 'sessionId',
178
+ type: 'string',
179
+ default: '',
180
+ required: true,
181
+ description: 'Unique identifier for the session',
182
+ displayOptions: {
183
+ show: {
184
+ resource: ['memory'],
185
+ operation: ['store'],
186
+ scope: ['session'],
187
+ },
188
+ },
189
+ },
190
+ {
191
+ displayName: 'User ID',
192
+ name: 'userId',
193
+ type: 'string',
194
+ default: '',
195
+ required: true,
196
+ description: 'Unique identifier for the user',
197
+ displayOptions: {
198
+ show: {
199
+ resource: ['memory'],
200
+ operation: ['store'],
201
+ scope: ['user'],
202
+ },
203
+ },
204
+ },
205
+ {
206
+ displayName: 'Agent ID',
207
+ name: 'agentId',
208
+ type: 'string',
209
+ default: '',
210
+ required: true,
211
+ description: 'Unique identifier for the agent',
212
+ displayOptions: {
213
+ show: {
214
+ resource: ['memory'],
215
+ operation: ['store'],
216
+ scope: ['agent'],
217
+ },
218
+ },
219
+ },
220
+ {
221
+ displayName: 'Additional Fields',
222
+ name: 'storeAdditionalFields',
223
+ type: 'collection',
224
+ placeholder: 'Add Field',
225
+ default: {},
226
+ displayOptions: {
227
+ show: {
228
+ resource: ['memory'],
229
+ operation: ['store'],
230
+ },
231
+ },
232
+ options: [
233
+ {
234
+ displayName: 'Dedup Threshold',
235
+ name: 'dedupThreshold',
236
+ type: 'number',
237
+ typeOptions: {
238
+ minValue: 0,
239
+ numberPrecision: 2,
240
+ },
241
+ default: 0,
242
+ description: 'Similarity threshold (0-1) for deduplication. 0 disables dedup. 0.95 is a good starting point.',
243
+ },
244
+ {
245
+ displayName: 'Metadata',
246
+ name: 'metadata',
247
+ type: 'json',
248
+ default: '{}',
249
+ description: 'Arbitrary key-value pairs as JSON object',
250
+ },
251
+ {
252
+ displayName: 'Namespace',
253
+ name: 'namespace',
254
+ type: 'string',
255
+ default: '',
256
+ description: 'Free-form grouping label for organizing memories',
257
+ },
258
+ {
259
+ displayName: 'Tags',
260
+ name: 'tags',
261
+ type: 'string',
262
+ default: '',
263
+ description: 'Comma-separated list of tags for categorical filtering (max 20 tags, 64 chars each)',
264
+ },
265
+ {
266
+ displayName: 'TTL (Seconds)',
267
+ name: 'ttlSeconds',
268
+ type: 'number',
269
+ typeOptions: {
270
+ minValue: 0,
271
+ },
272
+ default: 0,
273
+ description: 'Time to live in seconds. 0 means no expiration. Max 31 536 000 (1 year).',
274
+ },
275
+ ],
276
+ },
277
+ // ==================================================================
278
+ // Fields — Memory > Search
279
+ // ==================================================================
280
+ {
281
+ displayName: 'Query',
282
+ name: 'query',
283
+ type: 'string',
284
+ typeOptions: {
285
+ rows: 2,
286
+ },
287
+ required: true,
288
+ default: '',
289
+ placeholder: "What are this user's preferences?",
290
+ description: 'Natural language query for semantic search',
291
+ displayOptions: {
292
+ show: {
293
+ resource: ['memory'],
294
+ operation: ['search'],
295
+ },
296
+ },
297
+ },
298
+ {
299
+ displayName: 'Additional Fields',
300
+ name: 'searchAdditionalFields',
301
+ type: 'collection',
302
+ placeholder: 'Add Field',
303
+ default: {},
304
+ displayOptions: {
305
+ show: {
306
+ resource: ['memory'],
307
+ operation: ['search'],
308
+ },
309
+ },
310
+ options: [
311
+ {
312
+ displayName: 'Agent ID',
313
+ name: 'agentId',
314
+ type: 'string',
315
+ default: '',
316
+ description: 'Filter by agent ID',
317
+ },
318
+ {
319
+ displayName: 'Limit',
320
+ name: 'limit',
321
+ type: 'number',
322
+ typeOptions: {
323
+ minValue: 1,
324
+ },
325
+ default: 50,
326
+ description: 'Max number of results to return',
327
+ },
328
+ {
329
+ displayName: 'Namespace',
330
+ name: 'namespace',
331
+ type: 'string',
332
+ default: '',
333
+ description: 'Filter by namespace',
334
+ },
335
+ {
336
+ displayName: 'Scope',
337
+ name: 'scope',
338
+ type: 'options',
339
+ options: [
340
+ { name: 'Session', value: 'session' },
341
+ { name: 'User', value: 'user' },
342
+ { name: 'Agent', value: 'agent' },
343
+ { name: 'Global', value: 'global' },
344
+ ],
345
+ default: 'user',
346
+ description: 'Filter by scope',
347
+ },
348
+ {
349
+ displayName: 'Session ID',
350
+ name: 'sessionId',
351
+ type: 'string',
352
+ default: '',
353
+ description: 'Filter by session ID',
354
+ },
355
+ {
356
+ displayName: 'Tags',
357
+ name: 'tags',
358
+ type: 'string',
359
+ default: '',
360
+ description: 'Comma-separated list of tags to filter by',
361
+ },
362
+ {
363
+ displayName: 'Threshold',
364
+ name: 'threshold',
365
+ type: 'number',
366
+ typeOptions: {
367
+ minValue: 0,
368
+ numberPrecision: 2,
369
+ },
370
+ default: 0.5,
371
+ description: 'Minimum similarity threshold (0-1)',
372
+ },
373
+ {
374
+ displayName: 'User ID',
375
+ name: 'userId',
376
+ type: 'string',
377
+ default: '',
378
+ description: 'Filter by user ID',
379
+ },
380
+ ],
381
+ },
382
+ // ==================================================================
383
+ // Fields — Memory > Get Context
384
+ // ==================================================================
385
+ {
386
+ displayName: 'Query',
387
+ name: 'query',
388
+ type: 'string',
389
+ typeOptions: {
390
+ rows: 2,
391
+ },
392
+ required: true,
393
+ default: '',
394
+ placeholder: 'Summarize what we know about this customer',
395
+ description: 'Natural language query to retrieve relevant context',
396
+ displayOptions: {
397
+ show: {
398
+ resource: ['memory'],
399
+ operation: ['getContext'],
400
+ },
401
+ },
402
+ },
403
+ {
404
+ displayName: 'Format',
405
+ name: 'format',
406
+ type: 'options',
407
+ default: 'system_prompt',
408
+ description: 'Output format for the context block',
409
+ options: [
410
+ {
411
+ name: 'System Prompt',
412
+ value: 'system_prompt',
413
+ description: 'Formatted as an LLM system prompt with header',
414
+ },
415
+ {
416
+ name: 'Bullet List',
417
+ value: 'bullet_list',
418
+ description: 'Simple bulleted list of memories',
419
+ },
420
+ {
421
+ name: 'Numbered List',
422
+ value: 'numbered_list',
423
+ description: 'Numbered list of memories',
424
+ },
425
+ ],
426
+ displayOptions: {
427
+ show: {
428
+ resource: ['memory'],
429
+ operation: ['getContext'],
430
+ },
431
+ },
432
+ },
433
+ {
434
+ displayName: 'Additional Fields',
435
+ name: 'contextAdditionalFields',
436
+ type: 'collection',
437
+ placeholder: 'Add Field',
438
+ default: {},
439
+ displayOptions: {
440
+ show: {
441
+ resource: ['memory'],
442
+ operation: ['getContext'],
443
+ },
444
+ },
445
+ options: [
446
+ {
447
+ displayName: 'Agent ID',
448
+ name: 'agentId',
449
+ type: 'string',
450
+ default: '',
451
+ description: 'Filter by agent ID',
452
+ },
453
+ {
454
+ displayName: 'Max Memories',
455
+ name: 'maxMemories',
456
+ type: 'number',
457
+ typeOptions: {
458
+ minValue: 1,
459
+ },
460
+ default: 5,
461
+ description: 'Maximum number of memories to include in the context (API max 20)',
462
+ },
463
+ {
464
+ displayName: 'Namespace',
465
+ name: 'namespace',
466
+ type: 'string',
467
+ default: '',
468
+ description: 'Filter by namespace',
469
+ },
470
+ {
471
+ displayName: 'Scope',
472
+ name: 'scope',
473
+ type: 'options',
474
+ options: [
475
+ { name: 'Session', value: 'session' },
476
+ { name: 'User', value: 'user' },
477
+ { name: 'Agent', value: 'agent' },
478
+ { name: 'Global', value: 'global' },
479
+ ],
480
+ default: 'user',
481
+ description: 'Filter by scope',
482
+ },
483
+ {
484
+ displayName: 'Session ID',
485
+ name: 'sessionId',
486
+ type: 'string',
487
+ default: '',
488
+ description: 'Filter by session ID',
489
+ },
490
+ {
491
+ displayName: 'Tags',
492
+ name: 'tags',
493
+ type: 'string',
494
+ default: '',
495
+ description: 'Comma-separated list of tags to filter by',
496
+ },
497
+ {
498
+ displayName: 'Threshold',
499
+ name: 'threshold',
500
+ type: 'number',
501
+ typeOptions: {
502
+ minValue: 0,
503
+ numberPrecision: 2,
504
+ },
505
+ default: 0.35,
506
+ description: 'Minimum similarity threshold (0-1)',
507
+ },
508
+ {
509
+ displayName: 'User ID',
510
+ name: 'userId',
511
+ type: 'string',
512
+ default: '',
513
+ description: 'Filter by user ID',
514
+ },
515
+ ],
516
+ },
517
+ // ==================================================================
518
+ // Fields — Memory > List
519
+ // ==================================================================
520
+ {
521
+ displayName: 'Additional Fields',
522
+ name: 'listAdditionalFields',
523
+ type: 'collection',
524
+ placeholder: 'Add Field',
525
+ default: {},
526
+ displayOptions: {
527
+ show: {
528
+ resource: ['memory'],
529
+ operation: ['list'],
530
+ },
531
+ },
532
+ options: [
533
+ {
534
+ displayName: 'Agent ID',
535
+ name: 'agentId',
536
+ type: 'string',
537
+ default: '',
538
+ description: 'Filter by agent ID',
539
+ },
540
+ {
541
+ displayName: 'Limit',
542
+ name: 'limit',
543
+ type: 'number',
544
+ typeOptions: {
545
+ minValue: 1,
546
+ },
547
+ default: 50,
548
+ description: 'Max number of results to return',
549
+ },
550
+ {
551
+ displayName: 'Namespace',
552
+ name: 'namespace',
553
+ type: 'string',
554
+ default: '',
555
+ description: 'Filter by namespace',
556
+ },
557
+ {
558
+ displayName: 'Offset',
559
+ name: 'offset',
560
+ type: 'number',
561
+ typeOptions: {
562
+ minValue: 0,
563
+ },
564
+ default: 0,
565
+ description: 'Pagination offset',
566
+ },
567
+ {
568
+ displayName: 'Scope',
569
+ name: 'scope',
570
+ type: 'options',
571
+ options: [
572
+ { name: 'Session', value: 'session' },
573
+ { name: 'User', value: 'user' },
574
+ { name: 'Agent', value: 'agent' },
575
+ { name: 'Global', value: 'global' },
576
+ ],
577
+ default: 'user',
578
+ description: 'Filter by scope',
579
+ },
580
+ {
581
+ displayName: 'Session ID',
582
+ name: 'sessionId',
583
+ type: 'string',
584
+ default: '',
585
+ description: 'Filter by session ID',
586
+ },
587
+ {
588
+ displayName: 'Tags',
589
+ name: 'tags',
590
+ type: 'string',
591
+ default: '',
592
+ description: 'Comma-separated list of tags to filter by',
593
+ },
594
+ {
595
+ displayName: 'User ID',
596
+ name: 'userId',
597
+ type: 'string',
598
+ default: '',
599
+ description: 'Filter by user ID',
600
+ },
601
+ ],
602
+ },
603
+ // ==================================================================
604
+ // Fields — Memory > Delete
605
+ // ==================================================================
606
+ {
607
+ displayName: 'Scope',
608
+ name: 'deleteScope',
609
+ type: 'options',
610
+ default: 'session',
611
+ description: 'Scope of memories to delete. At least one filter is required.',
612
+ options: [
613
+ { name: 'Session', value: 'session' },
614
+ { name: 'User', value: 'user' },
615
+ { name: 'Agent', value: 'agent' },
616
+ { name: 'Global', value: 'global' },
617
+ ],
618
+ displayOptions: {
619
+ show: {
620
+ resource: ['memory'],
621
+ operation: ['delete'],
622
+ },
623
+ },
624
+ },
625
+ {
626
+ displayName: 'Additional Fields',
627
+ name: 'deleteAdditionalFields',
628
+ type: 'collection',
629
+ placeholder: 'Add Field',
630
+ default: {},
631
+ displayOptions: {
632
+ show: {
633
+ resource: ['memory'],
634
+ operation: ['delete'],
635
+ },
636
+ },
637
+ options: [
638
+ {
639
+ displayName: 'Agent ID',
640
+ name: 'agentId',
641
+ type: 'string',
642
+ default: '',
643
+ description: 'Filter by agent ID',
644
+ },
645
+ {
646
+ displayName: 'Namespace',
647
+ name: 'namespace',
648
+ type: 'string',
649
+ default: '',
650
+ description: 'Filter by namespace',
651
+ },
652
+ {
653
+ displayName: 'Session ID',
654
+ name: 'sessionId',
655
+ type: 'string',
656
+ default: '',
657
+ description: 'Filter by session ID',
658
+ },
659
+ {
660
+ displayName: 'User ID',
661
+ name: 'userId',
662
+ type: 'string',
663
+ default: '',
664
+ description: 'Filter by user ID',
665
+ },
666
+ ],
667
+ },
668
+ ],
669
+ };
670
+ }
671
+ async execute() {
672
+ const items = this.getInputData();
673
+ const returnData = [];
674
+ const resource = this.getNodeParameter('resource', 0);
675
+ const operation = this.getNodeParameter('operation', 0);
676
+ const credentials = await this.getCredentials('retainrApi');
677
+ const baseUrl = credentials.baseUrl.replace(/\/+$/, '');
678
+ for (let i = 0; i < items.length; i++) {
679
+ try {
680
+ let responseData;
681
+ // --------------------------------------------------------------
682
+ // Memory
683
+ // --------------------------------------------------------------
684
+ if (resource === 'memory') {
685
+ if (operation === 'store') {
686
+ responseData = await storeMemory.call(this, i, baseUrl);
687
+ }
688
+ else if (operation === 'search') {
689
+ responseData = await searchMemories.call(this, i, baseUrl);
690
+ }
691
+ else if (operation === 'getContext') {
692
+ responseData = await getContext.call(this, i, baseUrl);
693
+ }
694
+ else if (operation === 'list') {
695
+ responseData = await listMemories.call(this, i, baseUrl);
696
+ }
697
+ else if (operation === 'delete') {
698
+ responseData = await deleteMemories.call(this, i, baseUrl);
699
+ }
700
+ else {
701
+ throw new Error(`Unknown operation: ${operation}`);
702
+ }
703
+ }
704
+ // --------------------------------------------------------------
705
+ // Workspace
706
+ // --------------------------------------------------------------
707
+ else if (resource === 'workspace') {
708
+ if (operation === 'getInfo') {
709
+ responseData = await getWorkspaceInfo.call(this, baseUrl);
710
+ }
711
+ else {
712
+ throw new Error(`Unknown operation: ${operation}`);
713
+ }
714
+ }
715
+ else {
716
+ throw new Error(`Unknown resource: ${resource}`);
717
+ }
718
+ returnData.push({ json: responseData, pairedItem: { item: i } });
719
+ }
720
+ catch (error) {
721
+ if (this.continueOnFail()) {
722
+ returnData.push({
723
+ json: { error: error.message },
724
+ pairedItem: { item: i },
725
+ });
726
+ continue;
727
+ }
728
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), error, {
729
+ itemIndex: i,
730
+ });
731
+ }
732
+ }
733
+ return [returnData];
734
+ }
735
+ }
736
+ exports.Retainr = Retainr;
737
+ // ======================================================================
738
+ // Helper: Make an authenticated API request
739
+ // ======================================================================
740
+ async function apiRequest(method, baseUrl, path, body, qs) {
741
+ const options = {
742
+ method,
743
+ url: `${baseUrl}${path}`,
744
+ json: true,
745
+ };
746
+ if (body && Object.keys(body).length > 0) {
747
+ options.body = body;
748
+ }
749
+ if (qs && Object.keys(qs).length > 0) {
750
+ options.qs = qs;
751
+ }
752
+ return (await this.helpers.httpRequestWithAuthentication.call(this, 'retainrApi', options));
753
+ }
754
+ // ======================================================================
755
+ // Helper: Parse comma-separated tags into array
756
+ // ======================================================================
757
+ function parseTags(raw) {
758
+ if (!raw)
759
+ return [];
760
+ return raw
761
+ .split(',')
762
+ .map((t) => t.trim())
763
+ .filter(Boolean);
764
+ }
765
+ // ======================================================================
766
+ // Operation handlers
767
+ // ======================================================================
768
+ async function storeMemory(i, baseUrl) {
769
+ const content = this.getNodeParameter('content', i);
770
+ const scope = this.getNodeParameter('scope', i);
771
+ const additional = this.getNodeParameter('storeAdditionalFields', i);
772
+ const body = { content, scope };
773
+ // Scope-specific IDs
774
+ if (scope === 'session') {
775
+ body.session_id = this.getNodeParameter('sessionId', i);
776
+ }
777
+ else if (scope === 'user') {
778
+ body.user_id = this.getNodeParameter('userId', i);
779
+ }
780
+ else if (scope === 'agent') {
781
+ body.agent_id = this.getNodeParameter('agentId', i);
782
+ }
783
+ // Optional fields
784
+ if (additional.namespace)
785
+ body.namespace = additional.namespace;
786
+ if (additional.tags)
787
+ body.tags = parseTags(additional.tags);
788
+ if (additional.ttlSeconds)
789
+ body.ttl_seconds = additional.ttlSeconds;
790
+ if (additional.dedupThreshold) {
791
+ body.dedup_threshold = additional.dedupThreshold;
792
+ }
793
+ if (additional.metadata) {
794
+ body.metadata =
795
+ typeof additional.metadata === 'string'
796
+ ? JSON.parse(additional.metadata)
797
+ : additional.metadata;
798
+ }
799
+ return apiRequest.call(this, 'POST', baseUrl, '/v1/memories', body);
800
+ }
801
+ async function searchMemories(i, baseUrl) {
802
+ const query = this.getNodeParameter('query', i);
803
+ const additional = this.getNodeParameter('searchAdditionalFields', i);
804
+ const body = { query };
805
+ if (additional.scope)
806
+ body.scope = additional.scope;
807
+ if (additional.sessionId)
808
+ body.session_id = additional.sessionId;
809
+ if (additional.userId)
810
+ body.user_id = additional.userId;
811
+ if (additional.agentId)
812
+ body.agent_id = additional.agentId;
813
+ if (additional.namespace)
814
+ body.namespace = additional.namespace;
815
+ if (additional.tags)
816
+ body.tags = parseTags(additional.tags);
817
+ if (additional.limit)
818
+ body.limit = additional.limit;
819
+ if (additional.threshold)
820
+ body.threshold = additional.threshold;
821
+ return apiRequest.call(this, 'POST', baseUrl, '/v1/memories/search', body);
822
+ }
823
+ async function getContext(i, baseUrl) {
824
+ const query = this.getNodeParameter('query', i);
825
+ const format = this.getNodeParameter('format', i);
826
+ const additional = this.getNodeParameter('contextAdditionalFields', i);
827
+ const body = { query, format };
828
+ if (additional.scope)
829
+ body.scope = additional.scope;
830
+ if (additional.sessionId)
831
+ body.session_id = additional.sessionId;
832
+ if (additional.userId)
833
+ body.user_id = additional.userId;
834
+ if (additional.agentId)
835
+ body.agent_id = additional.agentId;
836
+ if (additional.namespace)
837
+ body.namespace = additional.namespace;
838
+ if (additional.tags)
839
+ body.tags = parseTags(additional.tags);
840
+ if (additional.maxMemories)
841
+ body.limit = additional.maxMemories;
842
+ if (additional.threshold)
843
+ body.threshold = additional.threshold;
844
+ return apiRequest.call(this, 'POST', baseUrl, '/v1/memories/context', body);
845
+ }
846
+ async function listMemories(i, baseUrl) {
847
+ const additional = this.getNodeParameter('listAdditionalFields', i);
848
+ const qs = {};
849
+ if (additional.scope)
850
+ qs.scope = additional.scope;
851
+ if (additional.sessionId)
852
+ qs.session_id = additional.sessionId;
853
+ if (additional.userId)
854
+ qs.user_id = additional.userId;
855
+ if (additional.agentId)
856
+ qs.agent_id = additional.agentId;
857
+ if (additional.namespace)
858
+ qs.namespace = additional.namespace;
859
+ if (additional.tags)
860
+ qs.tags = additional.tags;
861
+ if (additional.limit)
862
+ qs.limit = additional.limit;
863
+ if (additional.offset)
864
+ qs.offset = additional.offset;
865
+ return apiRequest.call(this, 'GET', baseUrl, '/v1/memories', undefined, qs);
866
+ }
867
+ async function deleteMemories(i, baseUrl) {
868
+ const scope = this.getNodeParameter('deleteScope', i);
869
+ const additional = this.getNodeParameter('deleteAdditionalFields', i);
870
+ const body = { scope };
871
+ if (additional.sessionId)
872
+ body.session_id = additional.sessionId;
873
+ if (additional.userId)
874
+ body.user_id = additional.userId;
875
+ if (additional.agentId)
876
+ body.agent_id = additional.agentId;
877
+ if (additional.namespace)
878
+ body.namespace = additional.namespace;
879
+ return apiRequest.call(this, 'DELETE', baseUrl, '/v1/memories', body);
880
+ }
881
+ async function getWorkspaceInfo(baseUrl) {
882
+ return apiRequest.call(this, 'GET', baseUrl, '/v1/workspace');
883
+ }