natureco-cli 5.20.3 → 5.21.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.
@@ -1,121 +1,121 @@
1
- /**
2
- * mem0-memory.js — Mem0 memory provider
3
- *
4
- * Uses the mem0ai npm package (platform API) or local OSS Memory class.
5
- * Requires MEM0_API_KEY env var or config.mem0.apiKey.
6
- * npm install mem0ai
7
- */
8
-
9
- const { MemoryProvider, registerProvider } = require('../utils/memory-provider');
10
-
11
- class Mem0MemoryProvider extends MemoryProvider {
12
- constructor(config = {}) {
13
- super(config);
14
- this.name = 'mem0';
15
- this._client = null;
16
- this._mode = 'platform'; // or 'oss'
17
- }
18
-
19
- _getConfig() {
20
- return this.config.mem0 || this.config.Mem0 || {};
21
- }
22
-
23
- _apiKey() {
24
- return process.env.MEM0_API_KEY || this._getConfig().apiKey || '';
25
- }
26
-
27
- async _ensureClient() {
28
- if (this._client) return;
29
- try {
30
- const apiKey = this._apiKey();
31
- if (apiKey) {
32
- const { MemoryClient } = await import('mem0ai');
33
- this._client = new MemoryClient({ apiKey });
34
- this._mode = 'platform';
35
- } else {
36
- const { Memory } = await import('mem0ai/oss');
37
- this._client = new Memory(this._getConfig().oss || {});
38
- this._mode = 'oss';
39
- }
40
- } catch (e) {
41
- throw new Error('mem0ai paketi yuklu degil. npm install mem0ai');
42
- }
43
- }
44
-
45
- async add(userId, content, metadata = {}) {
46
- await this._ensureClient();
47
- const uid = userId || 'default';
48
- if (this._mode === 'platform') {
49
- const messages = [{ role: 'user', content }];
50
- await this._client.add(messages, { userId: uid, metadata });
51
- } else {
52
- const messages = [
53
- { role: 'user', content },
54
- { role: 'assistant', content: 'Bilgi kaydedildi.' },
55
- ];
56
- await this._client.add(messages, { userId: uid, metadata });
57
- }
58
- return { success: true, id: content, message: 'Mem0 memory added', provider: 'mem0' };
59
- }
60
-
61
- async search(query, options = {}) {
62
- await this._ensureClient();
63
- const uid = options.userId;
64
- const filters = uid ? { userId: uid } : {};
65
- if (options.limit) filters.limit = options.limit;
66
- try {
67
- const results = await this._client.search(query, { filters });
68
- return { success: true, results: (results.results || results || []).map(r => ({
69
- id: r.id || r.memory,
70
- content: r.memory || r.content || '',
71
- score: r.score || 0,
72
- metadata: r.metadata || {},
73
- })) };
74
- } catch (e) {
75
- return { success: false, error: e.message, results: [] };
76
- }
77
- }
78
-
79
- async list(userId) {
80
- await this._ensureClient();
81
- const uid = userId || 'default';
82
- try {
83
- const memories = await this._client.getAll({ userId: uid });
84
- return {
85
- success: true,
86
- memories: (memories || []).map(r => ({
87
- id: r.id || r.memory,
88
- content: r.memory || r.content || '',
89
- score: r.score || 0,
90
- metadata: r.metadata || {},
91
- })),
92
- };
93
- } catch (e) {
94
- return { success: false, error: e.message, memories: [] };
95
- }
96
- }
97
-
98
- async remove(id) {
99
- await this._ensureClient();
100
- try {
101
- await this._client.delete(id);
102
- return { success: true, message: 'Mem0 memory removed' };
103
- } catch (e) {
104
- return { success: false, error: e.message };
105
- }
106
- }
107
-
108
- async clear(userId) {
109
- await this._ensureClient();
110
- const uid = userId || 'default';
111
- try {
112
- await this._client.deleteAll({ userId: uid });
113
- return { success: true, message: `Mem0 memory cleared for ${uid}` };
114
- } catch (e) {
115
- return { success: false, error: e.message };
116
- }
117
- }
118
- }
119
-
120
- registerProvider('mem0', Mem0MemoryProvider);
121
- module.exports = Mem0MemoryProvider;
1
+ /**
2
+ * mem0-memory.js — Mem0 memory provider
3
+ *
4
+ * Uses the mem0ai npm package (platform API) or local OSS Memory class.
5
+ * Requires MEM0_API_KEY env var or config.mem0.apiKey.
6
+ * npm install mem0ai
7
+ */
8
+
9
+ const { MemoryProvider, registerProvider } = require('../utils/memory-provider');
10
+
11
+ class Mem0MemoryProvider extends MemoryProvider {
12
+ constructor(config = {}) {
13
+ super(config);
14
+ this.name = 'mem0';
15
+ this._client = null;
16
+ this._mode = 'platform'; // or 'oss'
17
+ }
18
+
19
+ _getConfig() {
20
+ return this.config.mem0 || this.config.Mem0 || {};
21
+ }
22
+
23
+ _apiKey() {
24
+ return process.env.MEM0_API_KEY || this._getConfig().apiKey || '';
25
+ }
26
+
27
+ async _ensureClient() {
28
+ if (this._client) return;
29
+ try {
30
+ const apiKey = this._apiKey();
31
+ if (apiKey) {
32
+ const { MemoryClient } = await import('mem0ai');
33
+ this._client = new MemoryClient({ apiKey });
34
+ this._mode = 'platform';
35
+ } else {
36
+ const { Memory } = await import('mem0ai/oss');
37
+ this._client = new Memory(this._getConfig().oss || {});
38
+ this._mode = 'oss';
39
+ }
40
+ } catch (e) {
41
+ throw new Error('mem0ai paketi yuklu degil. npm install mem0ai', { cause: e });
42
+ }
43
+ }
44
+
45
+ async add(userId, content, metadata = {}) {
46
+ await this._ensureClient();
47
+ const uid = userId || 'default';
48
+ if (this._mode === 'platform') {
49
+ const messages = [{ role: 'user', content }];
50
+ await this._client.add(messages, { userId: uid, metadata });
51
+ } else {
52
+ const messages = [
53
+ { role: 'user', content },
54
+ { role: 'assistant', content: 'Bilgi kaydedildi.' },
55
+ ];
56
+ await this._client.add(messages, { userId: uid, metadata });
57
+ }
58
+ return { success: true, id: content, message: 'Mem0 memory added', provider: 'mem0' };
59
+ }
60
+
61
+ async search(query, options = {}) {
62
+ await this._ensureClient();
63
+ const uid = options.userId;
64
+ const filters = uid ? { userId: uid } : {};
65
+ if (options.limit) filters.limit = options.limit;
66
+ try {
67
+ const results = await this._client.search(query, { filters });
68
+ return { success: true, results: (results.results || results || []).map(r => ({
69
+ id: r.id || r.memory,
70
+ content: r.memory || r.content || '',
71
+ score: r.score || 0,
72
+ metadata: r.metadata || {},
73
+ })) };
74
+ } catch (e) {
75
+ return { success: false, error: e.message, results: [] };
76
+ }
77
+ }
78
+
79
+ async list(userId) {
80
+ await this._ensureClient();
81
+ const uid = userId || 'default';
82
+ try {
83
+ const memories = await this._client.getAll({ userId: uid });
84
+ return {
85
+ success: true,
86
+ memories: (memories || []).map(r => ({
87
+ id: r.id || r.memory,
88
+ content: r.memory || r.content || '',
89
+ score: r.score || 0,
90
+ metadata: r.metadata || {},
91
+ })),
92
+ };
93
+ } catch (e) {
94
+ return { success: false, error: e.message, memories: [] };
95
+ }
96
+ }
97
+
98
+ async remove(id) {
99
+ await this._ensureClient();
100
+ try {
101
+ await this._client.delete(id);
102
+ return { success: true, message: 'Mem0 memory removed' };
103
+ } catch (e) {
104
+ return { success: false, error: e.message };
105
+ }
106
+ }
107
+
108
+ async clear(userId) {
109
+ await this._ensureClient();
110
+ const uid = userId || 'default';
111
+ try {
112
+ await this._client.deleteAll({ userId: uid });
113
+ return { success: true, message: `Mem0 memory cleared for ${uid}` };
114
+ } catch (e) {
115
+ return { success: false, error: e.message };
116
+ }
117
+ }
118
+ }
119
+
120
+ registerProvider('mem0', Mem0MemoryProvider);
121
+ module.exports = Mem0MemoryProvider;
@@ -1,117 +1,117 @@
1
- /**
2
- * supermemory-memory.js — Supermemory memory provider
3
- *
4
- * Uses the supermemory npm package.
5
- * Requires SUPERMEMORY_API_KEY env var or config.supermemory.apiKey.
6
- * npm install supermemory
7
- */
8
-
9
- const { MemoryProvider, registerProvider } = require('../utils/memory-provider');
10
-
11
- class SupermemoryMemoryProvider extends MemoryProvider {
12
- constructor(config = {}) {
13
- super(config);
14
- this.name = 'supermemory';
15
- this._client = null;
16
- }
17
-
18
- _getConfig() {
19
- return this.config.supermemory || this.config.Supermemory || {};
20
- }
21
-
22
- _apiKey() {
23
- return process.env.SUPERMEMORY_API_KEY || this._getConfig().apiKey || '';
24
- }
25
-
26
- async _ensureClient() {
27
- if (this._client) return;
28
- try {
29
- const Supermemory = (await import('supermemory')).default;
30
- this._client = new Supermemory({
31
- apiKey: this._apiKey() || undefined,
32
- ...this._getConfig().options,
33
- });
34
- } catch (e) {
35
- throw new Error('supermemory paketi yuklu degil. npm install supermemory');
36
- }
37
- }
38
-
39
- async add(userId, content, metadata = {}) {
40
- await this._ensureClient();
41
- const tag = `user_${(userId || 'default').toLowerCase()}`;
42
- await this._client.add({
43
- content,
44
- containerTags: [tag],
45
- ...metadata,
46
- });
47
- return { success: true, id: content, message: 'Supermemory added', provider: 'supermemory' };
48
- }
49
-
50
- async search(query, options = {}) {
51
- await this._ensureClient();
52
- const tag = options.userId ? `user_${options.userId.toLowerCase()}` : undefined;
53
- try {
54
- const response = await this._client.search.documents({
55
- q: query,
56
- ...(tag ? { containerTags: [tag] } : {}),
57
- limit: options.limit || 10,
58
- });
59
- return {
60
- success: true,
61
- results: (response.results || []).map(r => ({
62
- id: r.id,
63
- content: r.content || '',
64
- score: r.score || 0,
65
- metadata: r.metadata || {},
66
- })),
67
- };
68
- } catch (e) {
69
- return { success: false, error: e.message, results: [] };
70
- }
71
- }
72
-
73
- async list(userId) {
74
- await this._ensureClient();
75
- const tag = `user_${(userId || 'default').toLowerCase()}`;
76
- try {
77
- const docs = await this._client.documents.list({ containerTags: [tag] });
78
- return {
79
- success: true,
80
- memories: (docs.results || docs || []).map(r => ({
81
- id: r.id,
82
- content: r.content || '',
83
- score: 0,
84
- metadata: r.metadata || {},
85
- })),
86
- };
87
- } catch (e) {
88
- return { success: false, error: e.message, memories: [] };
89
- }
90
- }
91
-
92
- async remove(id) {
93
- await this._ensureClient();
94
- try {
95
- await this._client.documents.delete({ docId: id });
96
- return { success: true, message: 'Supermemory removed' };
97
- } catch (e) {
98
- return { success: false, error: e.message };
99
- }
100
- }
101
-
102
- async clear(userId) {
103
- const tag = `user_${(userId || 'default').toLowerCase()}`;
104
- try {
105
- const listed = await this.list(userId);
106
- for (const mem of listed.memories || []) {
107
- try { await this.remove(mem.id); } catch {}
108
- }
109
- return { success: true, message: `Supermemory cleared for ${tag}` };
110
- } catch (e) {
111
- return { success: false, error: e.message };
112
- }
113
- }
114
- }
115
-
116
- registerProvider('supermemory', SupermemoryMemoryProvider);
117
- module.exports = SupermemoryMemoryProvider;
1
+ /**
2
+ * supermemory-memory.js — Supermemory memory provider
3
+ *
4
+ * Uses the supermemory npm package.
5
+ * Requires SUPERMEMORY_API_KEY env var or config.supermemory.apiKey.
6
+ * npm install supermemory
7
+ */
8
+
9
+ const { MemoryProvider, registerProvider } = require('../utils/memory-provider');
10
+
11
+ class SupermemoryMemoryProvider extends MemoryProvider {
12
+ constructor(config = {}) {
13
+ super(config);
14
+ this.name = 'supermemory';
15
+ this._client = null;
16
+ }
17
+
18
+ _getConfig() {
19
+ return this.config.supermemory || this.config.Supermemory || {};
20
+ }
21
+
22
+ _apiKey() {
23
+ return process.env.SUPERMEMORY_API_KEY || this._getConfig().apiKey || '';
24
+ }
25
+
26
+ async _ensureClient() {
27
+ if (this._client) return;
28
+ try {
29
+ const Supermemory = (await import('supermemory')).default;
30
+ this._client = new Supermemory({
31
+ apiKey: this._apiKey() || undefined,
32
+ ...this._getConfig().options,
33
+ });
34
+ } catch (e) {
35
+ throw new Error('supermemory paketi yuklu degil. npm install supermemory', { cause: e });
36
+ }
37
+ }
38
+
39
+ async add(userId, content, metadata = {}) {
40
+ await this._ensureClient();
41
+ const tag = `user_${(userId || 'default').toLowerCase()}`;
42
+ await this._client.add({
43
+ content,
44
+ containerTags: [tag],
45
+ ...metadata,
46
+ });
47
+ return { success: true, id: content, message: 'Supermemory added', provider: 'supermemory' };
48
+ }
49
+
50
+ async search(query, options = {}) {
51
+ await this._ensureClient();
52
+ const tag = options.userId ? `user_${options.userId.toLowerCase()}` : undefined;
53
+ try {
54
+ const response = await this._client.search.documents({
55
+ q: query,
56
+ ...(tag ? { containerTags: [tag] } : {}),
57
+ limit: options.limit || 10,
58
+ });
59
+ return {
60
+ success: true,
61
+ results: (response.results || []).map(r => ({
62
+ id: r.id,
63
+ content: r.content || '',
64
+ score: r.score || 0,
65
+ metadata: r.metadata || {},
66
+ })),
67
+ };
68
+ } catch (e) {
69
+ return { success: false, error: e.message, results: [] };
70
+ }
71
+ }
72
+
73
+ async list(userId) {
74
+ await this._ensureClient();
75
+ const tag = `user_${(userId || 'default').toLowerCase()}`;
76
+ try {
77
+ const docs = await this._client.documents.list({ containerTags: [tag] });
78
+ return {
79
+ success: true,
80
+ memories: (docs.results || docs || []).map(r => ({
81
+ id: r.id,
82
+ content: r.content || '',
83
+ score: 0,
84
+ metadata: r.metadata || {},
85
+ })),
86
+ };
87
+ } catch (e) {
88
+ return { success: false, error: e.message, memories: [] };
89
+ }
90
+ }
91
+
92
+ async remove(id) {
93
+ await this._ensureClient();
94
+ try {
95
+ await this._client.documents.delete({ docId: id });
96
+ return { success: true, message: 'Supermemory removed' };
97
+ } catch (e) {
98
+ return { success: false, error: e.message };
99
+ }
100
+ }
101
+
102
+ async clear(userId) {
103
+ const tag = `user_${(userId || 'default').toLowerCase()}`;
104
+ try {
105
+ const listed = await this.list(userId);
106
+ for (const mem of listed.memories || []) {
107
+ try { await this.remove(mem.id); } catch {}
108
+ }
109
+ return { success: true, message: `Supermemory cleared for ${tag}` };
110
+ } catch (e) {
111
+ return { success: false, error: e.message };
112
+ }
113
+ }
114
+ }
115
+
116
+ registerProvider('supermemory', SupermemoryMemoryProvider);
117
+ module.exports = SupermemoryMemoryProvider;