@agent-relay/memory 0.1.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/dist/adapters/index.d.ts +8 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +8 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/inmemory.d.ts +59 -0
- package/dist/adapters/inmemory.d.ts.map +1 -0
- package/dist/adapters/inmemory.js +195 -0
- package/dist/adapters/inmemory.js.map +1 -0
- package/dist/adapters/supermemory.d.ts +71 -0
- package/dist/adapters/supermemory.d.ts.map +1 -0
- package/dist/adapters/supermemory.js +338 -0
- package/dist/adapters/supermemory.js.map +1 -0
- package/dist/context-compaction.d.ts +156 -0
- package/dist/context-compaction.d.ts.map +1 -0
- package/dist/context-compaction.js +453 -0
- package/dist/context-compaction.js.map +1 -0
- package/dist/factory.d.ts +48 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +143 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/memory-hooks.d.ts +60 -0
- package/dist/memory-hooks.d.ts.map +1 -0
- package/dist/memory-hooks.js +313 -0
- package/dist/memory-hooks.js.map +1 -0
- package/dist/service.d.ts +49 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +146 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +195 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Adapters
|
|
3
|
+
*
|
|
4
|
+
* Export all available memory adapter implementations.
|
|
5
|
+
*/
|
|
6
|
+
export { InMemoryAdapter, type InMemoryAdapterOptions } from './inmemory.js';
|
|
7
|
+
export { SupermemoryAdapter, type SupermemoryAdapterOptions } from './supermemory.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAA+B,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAkC,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Memory Adapter
|
|
3
|
+
*
|
|
4
|
+
* A simple in-memory implementation of the MemoryAdapter interface.
|
|
5
|
+
* Useful for testing and development. Does not persist across restarts.
|
|
6
|
+
*
|
|
7
|
+
* For semantic search, this adapter uses simple keyword matching.
|
|
8
|
+
* For production use with semantic search, use SupermemoryAdapter or similar.
|
|
9
|
+
*/
|
|
10
|
+
import type { MemoryAdapter, MemoryEntry, MemorySearchQuery, AddMemoryOptions, MemoryResult } from '../types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for the InMemoryAdapter
|
|
13
|
+
*/
|
|
14
|
+
export interface InMemoryAdapterOptions {
|
|
15
|
+
/** Maximum number of memories to store (default: 1000) */
|
|
16
|
+
maxMemories?: number;
|
|
17
|
+
/** Default agent ID */
|
|
18
|
+
defaultAgentId?: string;
|
|
19
|
+
/** Default project ID */
|
|
20
|
+
defaultProjectId?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* In-memory storage adapter for memories
|
|
24
|
+
*/
|
|
25
|
+
export declare class InMemoryAdapter implements MemoryAdapter {
|
|
26
|
+
readonly type = "inmemory";
|
|
27
|
+
private memories;
|
|
28
|
+
private maxMemories;
|
|
29
|
+
private defaultAgentId?;
|
|
30
|
+
private defaultProjectId?;
|
|
31
|
+
constructor(options?: InMemoryAdapterOptions);
|
|
32
|
+
init(): Promise<void>;
|
|
33
|
+
add(content: string, options?: AddMemoryOptions): Promise<MemoryResult>;
|
|
34
|
+
search(query: MemorySearchQuery): Promise<MemoryEntry[]>;
|
|
35
|
+
get(id: string): Promise<MemoryEntry | null>;
|
|
36
|
+
delete(id: string): Promise<MemoryResult>;
|
|
37
|
+
update(id: string, content: string, options?: Partial<AddMemoryOptions>): Promise<MemoryResult>;
|
|
38
|
+
list(options?: {
|
|
39
|
+
limit?: number;
|
|
40
|
+
agentId?: string;
|
|
41
|
+
projectId?: string;
|
|
42
|
+
}): Promise<MemoryEntry[]>;
|
|
43
|
+
clear(options?: {
|
|
44
|
+
agentId?: string;
|
|
45
|
+
projectId?: string;
|
|
46
|
+
before?: number;
|
|
47
|
+
}): Promise<MemoryResult>;
|
|
48
|
+
stats(): Promise<{
|
|
49
|
+
totalCount: number;
|
|
50
|
+
byAgent?: Record<string, number>;
|
|
51
|
+
byProject?: Record<string, number>;
|
|
52
|
+
}>;
|
|
53
|
+
close(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Remove oldest memories when over limit
|
|
56
|
+
*/
|
|
57
|
+
private pruneOldest;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=inmemory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inmemory.d.ts","sourceRoot":"","sources":["../../src/adapters/inmemory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACb,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,sBAAsB;IAC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AAM,CAAC;KACjB,GAAG,OAAO,CAAC,YAAY,CAAC;IA8BnB,KAAK,IAAI,OAAO,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACpC,CAAC;IAoBI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACH,OAAO,CAAC,WAAW;CAUpB"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Memory Adapter
|
|
3
|
+
*
|
|
4
|
+
* A simple in-memory implementation of the MemoryAdapter interface.
|
|
5
|
+
* Useful for testing and development. Does not persist across restarts.
|
|
6
|
+
*
|
|
7
|
+
* For semantic search, this adapter uses simple keyword matching.
|
|
8
|
+
* For production use with semantic search, use SupermemoryAdapter or similar.
|
|
9
|
+
*/
|
|
10
|
+
import { randomUUID } from 'node:crypto';
|
|
11
|
+
/**
|
|
12
|
+
* In-memory storage adapter for memories
|
|
13
|
+
*/
|
|
14
|
+
export class InMemoryAdapter {
|
|
15
|
+
type = 'inmemory';
|
|
16
|
+
memories = new Map();
|
|
17
|
+
maxMemories;
|
|
18
|
+
defaultAgentId;
|
|
19
|
+
defaultProjectId;
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.maxMemories = options.maxMemories ?? 1000;
|
|
22
|
+
this.defaultAgentId = options.defaultAgentId;
|
|
23
|
+
this.defaultProjectId = options.defaultProjectId;
|
|
24
|
+
}
|
|
25
|
+
async init() {
|
|
26
|
+
// No initialization needed for in-memory storage
|
|
27
|
+
}
|
|
28
|
+
async add(content, options) {
|
|
29
|
+
const id = randomUUID();
|
|
30
|
+
const now = Date.now();
|
|
31
|
+
const entry = {
|
|
32
|
+
id,
|
|
33
|
+
content,
|
|
34
|
+
createdAt: now,
|
|
35
|
+
lastAccessedAt: now,
|
|
36
|
+
tags: options?.tags,
|
|
37
|
+
source: options?.source ?? 'agent',
|
|
38
|
+
agentId: options?.agentId ?? this.defaultAgentId,
|
|
39
|
+
projectId: options?.projectId ?? this.defaultProjectId,
|
|
40
|
+
sessionId: options?.sessionId,
|
|
41
|
+
metadata: options?.metadata,
|
|
42
|
+
};
|
|
43
|
+
this.memories.set(id, entry);
|
|
44
|
+
// Prune if over limit
|
|
45
|
+
if (this.memories.size > this.maxMemories) {
|
|
46
|
+
this.pruneOldest();
|
|
47
|
+
}
|
|
48
|
+
return { success: true, id };
|
|
49
|
+
}
|
|
50
|
+
async search(query) {
|
|
51
|
+
const results = [];
|
|
52
|
+
const queryLower = query.query.toLowerCase();
|
|
53
|
+
const queryTerms = queryLower.split(/\s+/).filter(t => t.length > 2);
|
|
54
|
+
for (const entry of this.memories.values()) {
|
|
55
|
+
// Apply filters
|
|
56
|
+
if (query.agentId && entry.agentId !== query.agentId)
|
|
57
|
+
continue;
|
|
58
|
+
if (query.projectId && entry.projectId !== query.projectId)
|
|
59
|
+
continue;
|
|
60
|
+
if (query.since && entry.createdAt < query.since)
|
|
61
|
+
continue;
|
|
62
|
+
if (query.before && entry.createdAt > query.before)
|
|
63
|
+
continue;
|
|
64
|
+
if (query.tags && query.tags.length > 0) {
|
|
65
|
+
if (!entry.tags || !query.tags.some(t => entry.tags.includes(t))) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Simple keyword-based scoring
|
|
70
|
+
const contentLower = entry.content.toLowerCase();
|
|
71
|
+
let score = 0;
|
|
72
|
+
// Exact phrase match gets highest score
|
|
73
|
+
if (contentLower.includes(queryLower)) {
|
|
74
|
+
score += 0.5;
|
|
75
|
+
}
|
|
76
|
+
// Term frequency scoring
|
|
77
|
+
for (const term of queryTerms) {
|
|
78
|
+
const matches = (contentLower.match(new RegExp(term, 'gi')) || []).length;
|
|
79
|
+
score += matches * 0.1;
|
|
80
|
+
}
|
|
81
|
+
// Normalize score to 0-1 range
|
|
82
|
+
score = Math.min(1, score);
|
|
83
|
+
if (score > 0 && (!query.minScore || score >= query.minScore)) {
|
|
84
|
+
// Update last accessed time
|
|
85
|
+
entry.lastAccessedAt = Date.now();
|
|
86
|
+
results.push({ ...entry, score });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Sort by score descending
|
|
90
|
+
results.sort((a, b) => b.score - a.score);
|
|
91
|
+
// Apply limit
|
|
92
|
+
const limit = query.limit ?? 10;
|
|
93
|
+
return results.slice(0, limit);
|
|
94
|
+
}
|
|
95
|
+
async get(id) {
|
|
96
|
+
const entry = this.memories.get(id);
|
|
97
|
+
if (entry) {
|
|
98
|
+
entry.lastAccessedAt = Date.now();
|
|
99
|
+
return { ...entry };
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
async delete(id) {
|
|
104
|
+
const deleted = this.memories.delete(id);
|
|
105
|
+
return {
|
|
106
|
+
success: deleted,
|
|
107
|
+
id,
|
|
108
|
+
error: deleted ? undefined : 'Memory not found',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async update(id, content, options) {
|
|
112
|
+
const existing = this.memories.get(id);
|
|
113
|
+
if (!existing) {
|
|
114
|
+
return { success: false, error: 'Memory not found' };
|
|
115
|
+
}
|
|
116
|
+
const updated = {
|
|
117
|
+
...existing,
|
|
118
|
+
content,
|
|
119
|
+
lastAccessedAt: Date.now(),
|
|
120
|
+
...(options?.tags && { tags: options.tags }),
|
|
121
|
+
...(options?.metadata && { metadata: { ...existing.metadata, ...options.metadata } }),
|
|
122
|
+
};
|
|
123
|
+
this.memories.set(id, updated);
|
|
124
|
+
return { success: true, id };
|
|
125
|
+
}
|
|
126
|
+
async list(options) {
|
|
127
|
+
const results = [];
|
|
128
|
+
for (const entry of this.memories.values()) {
|
|
129
|
+
if (options?.agentId && entry.agentId !== options.agentId)
|
|
130
|
+
continue;
|
|
131
|
+
if (options?.projectId && entry.projectId !== options.projectId)
|
|
132
|
+
continue;
|
|
133
|
+
results.push({ ...entry });
|
|
134
|
+
}
|
|
135
|
+
// Sort by creation time descending
|
|
136
|
+
results.sort((a, b) => b.createdAt - a.createdAt);
|
|
137
|
+
const limit = options?.limit ?? 50;
|
|
138
|
+
return results.slice(0, limit);
|
|
139
|
+
}
|
|
140
|
+
async clear(options) {
|
|
141
|
+
let _count = 0;
|
|
142
|
+
const toDelete = [];
|
|
143
|
+
for (const [id, entry] of this.memories.entries()) {
|
|
144
|
+
let shouldDelete = true;
|
|
145
|
+
if (options?.agentId && entry.agentId !== options.agentId) {
|
|
146
|
+
shouldDelete = false;
|
|
147
|
+
}
|
|
148
|
+
if (options?.projectId && entry.projectId !== options.projectId) {
|
|
149
|
+
shouldDelete = false;
|
|
150
|
+
}
|
|
151
|
+
if (options?.before && entry.createdAt >= options.before) {
|
|
152
|
+
shouldDelete = false;
|
|
153
|
+
}
|
|
154
|
+
if (shouldDelete) {
|
|
155
|
+
toDelete.push(id);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
for (const id of toDelete) {
|
|
159
|
+
this.memories.delete(id);
|
|
160
|
+
_count++;
|
|
161
|
+
}
|
|
162
|
+
return { success: true };
|
|
163
|
+
}
|
|
164
|
+
async stats() {
|
|
165
|
+
const byAgent = {};
|
|
166
|
+
const byProject = {};
|
|
167
|
+
for (const entry of this.memories.values()) {
|
|
168
|
+
if (entry.agentId) {
|
|
169
|
+
byAgent[entry.agentId] = (byAgent[entry.agentId] ?? 0) + 1;
|
|
170
|
+
}
|
|
171
|
+
if (entry.projectId) {
|
|
172
|
+
byProject[entry.projectId] = (byProject[entry.projectId] ?? 0) + 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
totalCount: this.memories.size,
|
|
177
|
+
byAgent,
|
|
178
|
+
byProject,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
async close() {
|
|
182
|
+
this.memories.clear();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Remove oldest memories when over limit
|
|
186
|
+
*/
|
|
187
|
+
pruneOldest() {
|
|
188
|
+
const sorted = Array.from(this.memories.entries()).sort(([, a], [, b]) => a.createdAt - b.createdAt);
|
|
189
|
+
const toRemove = sorted.slice(0, this.memories.size - this.maxMemories);
|
|
190
|
+
for (const [id] of toRemove) {
|
|
191
|
+
this.memories.delete(id);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=inmemory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inmemory.js","sourceRoot":"","sources":["../../src/adapters/inmemory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqBzC;;GAEG;AACH,MAAM,OAAO,eAAe;IACjB,IAAI,GAAG,UAAU,CAAC;IAEnB,QAAQ,GAA6B,IAAI,GAAG,EAAE,CAAC;IAC/C,WAAW,CAAS;IACpB,cAAc,CAAU;IACxB,gBAAgB,CAAU;IAElC,YAAY,UAAkC,EAAE;QAC9C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC;QAC/C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,IAAI;QACR,iDAAiD;IACnD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,OAAe,EAAE,OAA0B;QACnD,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,MAAM,KAAK,GAAgB;YACzB,EAAE;YACF,OAAO;YACP,SAAS,EAAE,GAAG;YACd,cAAc,EAAE,GAAG;YACnB,IAAI,EAAE,OAAO,EAAE,IAAI;YACnB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C,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;QAED,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YAC9B,OAAO;YACP,SAAS;SACV,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACK,WAAW;QACjB,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CACrD,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAC5C,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;QACxE,KAAK,MAAM,CAAC,EAAE,CAAC,IAAI,QAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supermemory.ai Memory Adapter
|
|
3
|
+
*
|
|
4
|
+
* Integration with supermemory.ai for semantic memory storage and retrieval.
|
|
5
|
+
* Provides AI-optimized search with embedding-based similarity.
|
|
6
|
+
*
|
|
7
|
+
* @see https://supermemory.ai/docs
|
|
8
|
+
*/
|
|
9
|
+
import type { MemoryAdapter, MemoryEntry, MemorySearchQuery, AddMemoryOptions, MemoryResult } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Options for the Supermemory adapter
|
|
12
|
+
*/
|
|
13
|
+
export interface SupermemoryAdapterOptions {
|
|
14
|
+
/** API key for supermemory.ai (required) */
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/** API endpoint (default: https://api.supermemory.ai) */
|
|
17
|
+
endpoint?: string;
|
|
18
|
+
/** Container/namespace for memories (optional) */
|
|
19
|
+
container?: string;
|
|
20
|
+
/** Default agent ID */
|
|
21
|
+
defaultAgentId?: string;
|
|
22
|
+
/** Default project ID */
|
|
23
|
+
defaultProjectId?: string;
|
|
24
|
+
/** Request timeout in ms (default: 30000) */
|
|
25
|
+
timeout?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Supermemory.ai adapter for semantic memory storage
|
|
29
|
+
*/
|
|
30
|
+
export declare class SupermemoryAdapter implements MemoryAdapter {
|
|
31
|
+
readonly type = "supermemory";
|
|
32
|
+
private apiKey;
|
|
33
|
+
private endpoint;
|
|
34
|
+
private container?;
|
|
35
|
+
private defaultAgentId?;
|
|
36
|
+
private defaultProjectId?;
|
|
37
|
+
private timeout;
|
|
38
|
+
private initialized;
|
|
39
|
+
constructor(options: SupermemoryAdapterOptions);
|
|
40
|
+
init(): Promise<void>;
|
|
41
|
+
add(content: string, options?: AddMemoryOptions): Promise<MemoryResult>;
|
|
42
|
+
search(query: MemorySearchQuery): Promise<MemoryEntry[]>;
|
|
43
|
+
get(id: string): Promise<MemoryEntry | null>;
|
|
44
|
+
delete(id: string): Promise<MemoryResult>;
|
|
45
|
+
update(id: string, content: string, options?: Partial<AddMemoryOptions>): Promise<MemoryResult>;
|
|
46
|
+
list(options?: {
|
|
47
|
+
limit?: number;
|
|
48
|
+
agentId?: string;
|
|
49
|
+
projectId?: string;
|
|
50
|
+
}): Promise<MemoryEntry[]>;
|
|
51
|
+
clear(options?: {
|
|
52
|
+
agentId?: string;
|
|
53
|
+
projectId?: string;
|
|
54
|
+
before?: number;
|
|
55
|
+
}): Promise<MemoryResult>;
|
|
56
|
+
stats(): Promise<{
|
|
57
|
+
totalCount: number;
|
|
58
|
+
byAgent?: Record<string, number>;
|
|
59
|
+
byProject?: Record<string, number>;
|
|
60
|
+
}>;
|
|
61
|
+
close(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Make a fetch request to the Supermemory API
|
|
64
|
+
*/
|
|
65
|
+
private fetch;
|
|
66
|
+
/**
|
|
67
|
+
* Convert a Supermemory document to a MemoryEntry
|
|
68
|
+
*/
|
|
69
|
+
private documentToMemoryEntry;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=supermemory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supermemory.d.ts","sourceRoot":"","sources":["../../src/adapters/supermemory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACb,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uBAAuB;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yBAAyB;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA0BD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IACtD,QAAQ,CAAC,IAAI,iBAAiB;IAE9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,cAAc,CAAC,CAAS;IAChC,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAClC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;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