@stackflo-labs/n8n-nodes-retainr 0.1.0 → 0.2.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 stackflo-labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @stackflo-labs/n8n-nodes-retainr
2
+
3
+ [n8n](https://n8n.io/) community node for [retainr.dev](https://retainr.dev) — the AI agent memory persistence API.
4
+
5
+ Give your n8n AI agents **long-term memory** that persists across workflow runs. Store facts, preferences, and context, then retrieve them with semantic search — so your agents remember what matters.
6
+
7
+ ## Features
8
+
9
+ | Operation | Description |
10
+ |-----------|-------------|
11
+ | **Store** | Save a memory with scope, tags, metadata, TTL, and deduplication |
12
+ | **Search** | Semantic similarity search across stored memories |
13
+ | **Get Context** | Retrieve pre-formatted memory context ready for LLM system prompts |
14
+ | **List** | Browse memories with filters (scope, user, session, tags) |
15
+ | **Delete** | Remove memories by filter criteria |
16
+ | **Get Workspace Info** | View plan usage, API keys, and workspace details |
17
+
18
+ ## Installation
19
+
20
+ ### n8n Cloud & Desktop
21
+
22
+ 1. Go to **Settings > Community Nodes**
23
+ 2. Search for `@stackflo-labs/n8n-nodes-retainr`
24
+ 3. Click **Install**
25
+
26
+ ### Self-hosted n8n
27
+
28
+ ```bash
29
+ cd ~/.n8n
30
+ npm install @stackflo-labs/n8n-nodes-retainr
31
+ ```
32
+
33
+ Then restart n8n.
34
+
35
+ ## Setup
36
+
37
+ 1. Sign up at [retainr.dev](https://retainr.dev) and get your API key
38
+ 2. In n8n, go to **Credentials > New > Retainr API**
39
+ 3. Paste your API key (`rec_live_...`)
40
+ 4. The default Base URL (`https://api.retainr.dev`) works out of the box
41
+
42
+ ## Usage Examples
43
+
44
+ ### Store a memory after a conversation
45
+
46
+ 1. Add the **Retainr** node after your AI Agent
47
+ 2. Set **Resource** to `Memory`, **Operation** to `Store`
48
+ 3. Map the conversation summary to the **Content** field
49
+ 4. Set **Scope** to `User` and provide the **User ID**
50
+
51
+ ### Inject memory context into an LLM prompt
52
+
53
+ 1. Add a **Retainr** node before your AI Agent
54
+ 2. Set **Operation** to `Get Context`
55
+ 3. Use the incoming message as the **Query**
56
+ 4. Pass the `context` output into your LLM's system prompt
57
+
58
+ ### Deduplicate similar memories
59
+
60
+ Use the **Dedup Threshold** field (e.g., `0.95`) when storing. If a sufficiently similar memory already exists, it will be updated instead of duplicated.
61
+
62
+ ## Memory Scopes
63
+
64
+ | Scope | Use case |
65
+ |-------|----------|
66
+ | `session` | Single workflow run — requires `session_id` |
67
+ | `user` | Persists across runs for one user — requires `user_id` |
68
+ | `agent` | Shared across users for one agent — requires `agent_id` |
69
+ | `global` | Shared across the entire workspace |
70
+
71
+ ## AI Agent Tool
72
+
73
+ This node has `usableAsTool` enabled — you can use it directly as a tool inside n8n's **AI Agent** node, letting the agent decide when to store or recall memories autonomously.
74
+
75
+ ## API Documentation
76
+
77
+ Full API reference: [retainr.dev/docs/api](https://retainr.dev/docs/api)
78
+
79
+ ## License
80
+
81
+ [MIT](LICENSE)
@@ -1,7 +1,9 @@
1
- import type { ICredentialType, INodeProperties } from 'n8n-workflow';
1
+ import type { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
2
2
  export declare class RetainrApi implements ICredentialType {
3
3
  name: string;
4
4
  displayName: string;
5
5
  documentationUrl: string;
6
6
  properties: INodeProperties[];
7
+ authenticate: IAuthenticateGeneric;
8
+ test: ICredentialTestRequest;
7
9
  }
@@ -14,16 +14,31 @@ class RetainrApi {
14
14
  typeOptions: { password: true },
15
15
  default: '',
16
16
  placeholder: 'rec_live_...',
17
- description: 'Your retainr.dev API key. Get one at https://retainr.dev/dashboard',
17
+ description: 'Your retainr.dev API key. Create one at https://retainr.dev/dashboard.',
18
18
  },
19
19
  {
20
20
  displayName: 'Base URL',
21
21
  name: 'baseUrl',
22
22
  type: 'string',
23
23
  default: 'https://api.retainr.dev',
24
- description: 'Leave as default unless using a self-hosted instance',
24
+ description: 'API base URL. Only change this if you run a self-hosted instance.',
25
25
  },
26
26
  ];
27
+ this.authenticate = {
28
+ type: 'generic',
29
+ properties: {
30
+ headers: {
31
+ Authorization: '=Bearer {{$credentials.apiKey}}',
32
+ },
33
+ },
34
+ };
35
+ this.test = {
36
+ request: {
37
+ baseURL: '={{$credentials.baseUrl}}',
38
+ url: '/v1/workspace',
39
+ method: 'GET',
40
+ },
41
+ };
27
42
  }
28
43
  }
29
44
  exports.RetainrApi = RetainrApi;
@@ -0,0 +1,5 @@
1
+ import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class Retainr implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -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: 'Limit',
455
+ name: 'limit',
456
+ type: 'number',
457
+ typeOptions: {
458
+ minValue: 1,
459
+ },
460
+ default: 50,
461
+ description: 'Max number of results to return',
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
+ for (let i = 0; i < items.length; i++) {
677
+ try {
678
+ const credentials = await this.getCredentials('retainrApi');
679
+ const baseUrl = credentials.baseUrl.replace(/\/+$/, '');
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.limit)
841
+ body.limit = additional.limit;
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
+ }
@@ -0,0 +1,9 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" viewBox="0 0 60 60" fill="none">
2
+ <rect width="60" height="60" rx="14" fill="#6366F1"/>
3
+ <g stroke="#fff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" fill="none">
4
+ <ellipse cx="30" cy="19" rx="12" ry="5"/>
5
+ <path d="M18 19v9c0 2.8 5.4 5 12 5s12-2.2 12-5v-9"/>
6
+ <path d="M18 28v9c0 2.8 5.4 5 12 5s12-2.2 12-5v-9"/>
7
+ </g>
8
+ <circle cx="30" cy="28" r="2.5" fill="#fff"/>
9
+ </svg>
package/package.json CHANGED
@@ -1,44 +1,55 @@
1
- {
2
- "name": "@stackflo-labs/n8n-nodes-retainr",
3
- "version": "0.1.0",
4
- "repository": {
5
- "type": "git",
6
- "url": "git+https://github.com/stackflo-labs/n8n-nodes-retainr.git"
7
- },
8
- "description": "n8n community node for retainr.dev — AI agent memory persistence API",
9
- "license": "MIT",
10
- "author": {
11
- "name": "retainr.dev"
12
- },
13
- "n8n": {
14
- "n8nNodesApiVersion": 1,
15
- "credentials": [
16
- "dist/credentials/RetainrApi.credentials.js"
17
- ],
18
- "nodes": []
19
- },
20
- "main": "dist/index.js",
21
- "files": [
22
- "dist"
23
- ],
24
- "scripts": {
25
- "build": "tsc"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "keywords": [
31
- "n8n-community-node-package",
32
- "n8n",
33
- "retainr",
34
- "ai-memory",
35
- "agent-memory"
36
- ],
37
- "peerDependencies": {
38
- "n8n-workflow": "*"
39
- },
40
- "devDependencies": {
41
- "n8n-workflow": "^1.0.0",
42
- "typescript": "^5.0.0"
43
- }
44
- }
1
+ {
2
+ "name": "@stackflo-labs/n8n-nodes-retainr",
3
+ "version": "0.2.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/stackflo-labs/n8n-nodes-retainr.git"
7
+ },
8
+ "description": "n8n community node for retainr.dev — AI agent memory persistence API. Store, search, and retrieve semantic memories for AI agents across workflow runs.",
9
+ "license": "MIT",
10
+ "author": {
11
+ "name": "stackflo-labs",
12
+ "url": "https://retainr.dev"
13
+ },
14
+ "homepage": "https://github.com/stackflo-labs/n8n-nodes-retainr",
15
+ "n8n": {
16
+ "n8nNodesApiVersion": 1,
17
+ "credentials": [
18
+ "dist/credentials/RetainrApi.credentials.js"
19
+ ],
20
+ "nodes": [
21
+ "dist/nodes/Retainr/Retainr.node.js"
22
+ ]
23
+ },
24
+ "main": "dist/nodes/Retainr/Retainr.node.js",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsc && copyfiles -u 1 \"src/**/*.svg\" dist",
30
+ "lint": "npx @n8n/scan-community-package @stackflo-labs/n8n-nodes-retainr",
31
+ "clean": "rimraf dist"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "keywords": [
37
+ "n8n-community-node-package",
38
+ "n8n",
39
+ "retainr",
40
+ "ai-memory",
41
+ "agent-memory",
42
+ "vector-search",
43
+ "semantic-memory",
44
+ "llm",
45
+ "ai-agent"
46
+ ],
47
+ "peerDependencies": {
48
+ "n8n-workflow": ">=1.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "copyfiles": "^2.4.1",
52
+ "n8n-workflow": "^1.70.0",
53
+ "typescript": "^5.7.0"
54
+ }
55
+ }