@devxiyang/agent-memo 0.0.1 → 0.0.3
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 +21 -0
- package/README.md +406 -35
- package/dist/core/memo/file-fs.d.ts +4 -3
- package/dist/core/memo/file-fs.d.ts.map +1 -1
- package/dist/core/memo/file-fs.js +20 -3
- package/dist/core/memo/file-fs.js.map +1 -1
- package/dist/core/memo/mime.d.ts +4 -3
- package/dist/core/memo/mime.d.ts.map +1 -1
- package/dist/core/memo/mime.js +64 -4
- package/dist/core/memo/mime.js.map +1 -1
- package/dist/core/memo/types.d.ts +19 -5
- package/dist/core/memo/types.d.ts.map +1 -1
- package/dist/plugins/memory/index.d.ts +47 -0
- package/dist/plugins/memory/index.d.ts.map +1 -0
- package/dist/plugins/memory/index.js +133 -0
- package/dist/plugins/memory/index.js.map +1 -0
- package/dist/plugins/memory/types.d.ts +44 -0
- package/dist/plugins/memory/types.d.ts.map +1 -0
- package/dist/plugins/memory/types.js +2 -0
- package/dist/plugins/memory/types.js.map +1 -0
- package/dist/plugins/resource/fetchers/local.d.ts +11 -0
- package/dist/plugins/resource/fetchers/local.d.ts.map +1 -0
- package/dist/plugins/resource/fetchers/local.js +33 -0
- package/dist/plugins/resource/fetchers/local.js.map +1 -0
- package/dist/plugins/resource/fetchers/url.d.ts +10 -0
- package/dist/plugins/resource/fetchers/url.d.ts.map +1 -0
- package/dist/plugins/resource/fetchers/url.js +41 -0
- package/dist/plugins/resource/fetchers/url.js.map +1 -0
- package/dist/plugins/resource/index.d.ts +50 -0
- package/dist/plugins/resource/index.d.ts.map +1 -0
- package/dist/plugins/resource/index.js +123 -0
- package/dist/plugins/resource/index.js.map +1 -0
- package/dist/plugins/resource/types.d.ts +39 -0
- package/dist/plugins/resource/types.d.ts.map +1 -0
- package/dist/plugins/resource/types.js +2 -0
- package/dist/plugins/resource/types.js.map +1 -0
- package/dist/plugins/utils.d.ts +5 -0
- package/dist/plugins/utils.d.ts.map +1 -0
- package/dist/plugins/utils.js +20 -0
- package/dist/plugins/utils.js.map +1 -0
- package/package.json +11 -2
- package/dist/core/memo/memo.d.ts +0 -1
- package/dist/core/memo/memo.d.ts.map +0 -1
- package/dist/core/memo/memo.js +0 -3
- package/dist/core/memo/memo.js.map +0 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { parseTtl, uriBasename, uriDirname } from '../utils.js';
|
|
4
|
+
import { UrlFetcher } from './fetchers/url.js';
|
|
5
|
+
export { UrlFetcher } from './fetchers/url.js';
|
|
6
|
+
export { LocalFetcher } from './fetchers/local.js';
|
|
7
|
+
function isExpired(meta) {
|
|
8
|
+
return !!meta.expiresAt && new Date(meta.expiresAt) < new Date();
|
|
9
|
+
}
|
|
10
|
+
// ─── AgentResource ───────────────────────────────────────────────────────────
|
|
11
|
+
export class AgentResource {
|
|
12
|
+
memo;
|
|
13
|
+
fetchers;
|
|
14
|
+
constructor(memo, fetchers) {
|
|
15
|
+
this.memo = memo;
|
|
16
|
+
this.fetchers = fetchers ?? [new UrlFetcher()];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fetch content from any source (URL, local path, or custom) and store at uri.
|
|
20
|
+
* The appropriate fetcher is selected via canHandle().
|
|
21
|
+
*/
|
|
22
|
+
async fetch(source, uri, options = {}) {
|
|
23
|
+
const fetcher = this.fetchers.find(f => f.canHandle(source));
|
|
24
|
+
if (!fetcher)
|
|
25
|
+
throw new Error(`No fetcher found for source: "${source}"`);
|
|
26
|
+
const destPath = this.memo.toPath(uri);
|
|
27
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
28
|
+
const { contentType } = await fetcher.fetch(source, destPath, options);
|
|
29
|
+
const now = new Date();
|
|
30
|
+
await this._writeMeta(uri, {
|
|
31
|
+
source,
|
|
32
|
+
fetchedAt: now.toISOString(),
|
|
33
|
+
contentType,
|
|
34
|
+
expiresAt: options.ttl
|
|
35
|
+
? new Date(now.getTime() + parseTtl(options.ttl)).toISOString()
|
|
36
|
+
: undefined,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Re-fetch a resource from its stored source.
|
|
41
|
+
* Throws if no metadata exists for the URI.
|
|
42
|
+
*/
|
|
43
|
+
async refresh(uri, options = {}) {
|
|
44
|
+
const meta = await this.getMeta(uri);
|
|
45
|
+
if (!meta)
|
|
46
|
+
throw new Error(`No resource metadata found for "${uri}". Fetch it first.`);
|
|
47
|
+
await this.fetch(meta.source, uri, options);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Read cached text content. Returns null if not found or expired.
|
|
51
|
+
* For binary files, use toPath() to get the physical path instead.
|
|
52
|
+
*/
|
|
53
|
+
async read(uri) {
|
|
54
|
+
const meta = await this.getMeta(uri);
|
|
55
|
+
if (!meta || isExpired(meta))
|
|
56
|
+
return null;
|
|
57
|
+
const content = await this.memo.read(uri);
|
|
58
|
+
if (content === null)
|
|
59
|
+
return null;
|
|
60
|
+
return { uri, content, meta };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Read cached binary content. Returns null if not found or expired.
|
|
64
|
+
* Use this for images, PDFs, audio, and other binary formats.
|
|
65
|
+
*/
|
|
66
|
+
async readBinary(uri) {
|
|
67
|
+
const meta = await this.getMeta(uri);
|
|
68
|
+
if (!meta || isExpired(meta))
|
|
69
|
+
return null;
|
|
70
|
+
const content = await this.memo.readBinary(uri);
|
|
71
|
+
if (content === null)
|
|
72
|
+
return null;
|
|
73
|
+
return { uri, content, meta };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the physical filesystem path for direct binary file access.
|
|
77
|
+
* Useful for passing to external tools (PDF parsers, image processors, etc.).
|
|
78
|
+
*/
|
|
79
|
+
toPath(uri) {
|
|
80
|
+
return this.memo.toPath(uri);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Remove the resource file and its metadata entry.
|
|
84
|
+
*/
|
|
85
|
+
async delete(uri) {
|
|
86
|
+
await this.memo.delete(uri);
|
|
87
|
+
const dirUri = uriDirname(uri);
|
|
88
|
+
const name = uriBasename(uri);
|
|
89
|
+
const existing = await this.memo.readMeta(dirUri);
|
|
90
|
+
const files = existing.meta?._resource ?? {};
|
|
91
|
+
delete files[name];
|
|
92
|
+
await this.memo.writeMeta(dirUri, { meta: { ...existing.meta, _resource: files } });
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check whether a cached resource is missing or expired.
|
|
96
|
+
*/
|
|
97
|
+
async isStale(uri) {
|
|
98
|
+
const meta = await this.getMeta(uri);
|
|
99
|
+
if (!meta)
|
|
100
|
+
return true;
|
|
101
|
+
return isExpired(meta);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get metadata for a resource without reading its content.
|
|
105
|
+
*/
|
|
106
|
+
async getMeta(uri) {
|
|
107
|
+
const dirUri = uriDirname(uri);
|
|
108
|
+
const name = uriBasename(uri);
|
|
109
|
+
const meta = await this.memo.readMeta(dirUri);
|
|
110
|
+
const files = meta.meta?._resource ?? {};
|
|
111
|
+
return files[name] ?? null;
|
|
112
|
+
}
|
|
113
|
+
// ── Private ────────────────────────────────────────────────────────────────
|
|
114
|
+
async _writeMeta(uri, resMeta) {
|
|
115
|
+
const dirUri = uriDirname(uri);
|
|
116
|
+
const name = uriBasename(uri);
|
|
117
|
+
const existing = await this.memo.readMeta(dirUri);
|
|
118
|
+
const files = existing.meta?._resource ?? {};
|
|
119
|
+
files[name] = resMeta;
|
|
120
|
+
await this.memo.writeMeta(dirUri, { meta: { ...existing.meta, _resource: files } });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/resource/index.ts"],"names":[],"mappings":"AAAA,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;YAAE,OAAO,IAAI,CAAA;QACtB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,GAAY;QACxB,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;QAC9B,MAAM,IAAI,GAAK,WAAW,CAAC,GAAG,CAAC,CAAA;QAC/B,MAAM,IAAI,GAAK,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAC/C,MAAM,KAAK,GAAK,IAAI,CAAC,IAAI,EAAE,SAAsD,IAAI,EAAE,CAAA;QACvF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAA;IAC5B,CAAC;IAED,8EAA8E;IAEtE,KAAK,CAAC,UAAU,CAAC,GAAY,EAAE,OAAqB;QAC1D,MAAM,MAAM,GAAK,UAAU,CAAC,GAAG,CAAC,CAAA;QAChC,MAAM,IAAI,GAAO,WAAW,CAAC,GAAG,CAAC,CAAA;QACjC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACjD,MAAM,KAAK,GAAO,QAAQ,CAAC,IAAI,EAAE,SAAsD,IAAI,EAAE,CAAA;QAC7F,KAAK,CAAC,IAAI,CAAC,GAAM,OAAO,CAAA;QACxB,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;IACrF,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MemoUri } from '../../core/memo/types.js';
|
|
2
|
+
export type FetchMeta = {
|
|
3
|
+
contentType?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Pluggable fetcher interface. Implement this to support custom sources
|
|
7
|
+
* (S3, database, internal APIs, etc.).
|
|
8
|
+
*/
|
|
9
|
+
export interface ResourceFetcher {
|
|
10
|
+
/** Return true if this fetcher can handle the given source string. */
|
|
11
|
+
canHandle(source: string): boolean;
|
|
12
|
+
/** Fetch content from source and write it to destPath (physical path). */
|
|
13
|
+
fetch(source: string, destPath: string, options?: FetchOptions): Promise<FetchMeta>;
|
|
14
|
+
}
|
|
15
|
+
export type FetchOptions = {
|
|
16
|
+
/** Time-to-live for cached content, e.g. '1d', '7d'. Omit to cache indefinitely. */
|
|
17
|
+
ttl?: string;
|
|
18
|
+
/** Additional HTTP request headers (used by UrlFetcher). */
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
};
|
|
21
|
+
export type ResourceMeta = {
|
|
22
|
+
source: string;
|
|
23
|
+
fetchedAt: string;
|
|
24
|
+
expiresAt?: string;
|
|
25
|
+
contentType?: string;
|
|
26
|
+
};
|
|
27
|
+
/** Text resource entry — returned by read(). */
|
|
28
|
+
export type ResourceEntry = {
|
|
29
|
+
uri: MemoUri;
|
|
30
|
+
content: string;
|
|
31
|
+
meta: ResourceMeta;
|
|
32
|
+
};
|
|
33
|
+
/** Binary resource entry — returned by readBinary(). */
|
|
34
|
+
export type BinaryResourceEntry = {
|
|
35
|
+
uri: MemoUri;
|
|
36
|
+
content: Uint8Array;
|
|
37
|
+
meta: ResourceMeta;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/resource/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAIvD,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,sEAAsE;IACtE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;IAClC,0EAA0E;IAC1E,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;CACpF;AAID,MAAM,MAAM,YAAY,GAAG;IACzB,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC,CAAA;AAID,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAQ,MAAM,CAAA;IACpB,SAAS,EAAK,MAAM,CAAA;IACpB,SAAS,CAAC,EAAI,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAID,gDAAgD;AAChD,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAM,OAAO,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAK,YAAY,CAAA;CACtB,CAAA;AAED,wDAAwD;AACxD,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAM,OAAO,CAAA;IAChB,OAAO,EAAE,UAAU,CAAA;IACnB,IAAI,EAAK,YAAY,CAAA;CACtB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plugins/resource/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/plugins/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAS5C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAI/C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function parseTtl(ttl) {
|
|
2
|
+
const match = ttl.match(/^(\d+)([smhdwy])$/);
|
|
3
|
+
if (!match)
|
|
4
|
+
throw new Error(`Invalid TTL: "${ttl}". Expected format: 30d, 1h, 7d, etc.`);
|
|
5
|
+
const n = parseInt(match[1], 10);
|
|
6
|
+
const units = {
|
|
7
|
+
s: 1_000, m: 60_000, h: 3_600_000,
|
|
8
|
+
d: 86_400_000, w: 604_800_000, y: 31_536_000_000,
|
|
9
|
+
};
|
|
10
|
+
return n * units[match[2]];
|
|
11
|
+
}
|
|
12
|
+
export function uriBasename(uri) {
|
|
13
|
+
return uri.split('/').filter(Boolean).at(-1) ?? '';
|
|
14
|
+
}
|
|
15
|
+
export function uriDirname(uri) {
|
|
16
|
+
const parts = uri.replace('memo://', '').split('/').filter(Boolean);
|
|
17
|
+
parts.pop();
|
|
18
|
+
return parts.length ? `memo://${parts.join('/')}` : 'memo://';
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/plugins/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAA;IAC5C,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,GAAG,uCAAuC,CAAC,CAAA;IACxF,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAChC,MAAM,KAAK,GAA2B;QACpC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS;QACjC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,cAAc;KACjD,CAAA;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACnE,KAAK,CAAC,GAAG,EAAE,CAAA;IACX,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AAC/D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devxiyang/agent-memo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Agent memory and memo SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,6 +25,14 @@
|
|
|
25
25
|
"./memo": {
|
|
26
26
|
"types": "./dist/core/memo/index.d.ts",
|
|
27
27
|
"import": "./dist/core/memo/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./memory": {
|
|
30
|
+
"types": "./dist/plugins/memory/index.d.ts",
|
|
31
|
+
"import": "./dist/plugins/memory/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./resource": {
|
|
34
|
+
"types": "./dist/plugins/resource/index.d.ts",
|
|
35
|
+
"import": "./dist/plugins/resource/index.js"
|
|
28
36
|
}
|
|
29
37
|
},
|
|
30
38
|
"files": [
|
|
@@ -45,6 +53,7 @@
|
|
|
45
53
|
"dependencies": {
|
|
46
54
|
"@vscode/ripgrep": ">=1.17.0",
|
|
47
55
|
"chokidar": ">=5.0.0",
|
|
48
|
-
"file-type": ">=21.0.0"
|
|
56
|
+
"file-type": ">=21.0.0",
|
|
57
|
+
"gray-matter": "^4.0.3"
|
|
49
58
|
}
|
|
50
59
|
}
|
package/dist/core/memo/memo.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=memo.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../../src/core/memo/memo.ts"],"names":[],"mappings":""}
|
package/dist/core/memo/memo.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memo.js","sourceRoot":"","sources":["../../../src/core/memo/memo.ts"],"names":[],"mappings":";AAAA,2CAA2C"}
|