@aumos/agent-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/client.d.ts +121 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +133 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +220 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/package.json +36 -0
- package/src/client.ts +294 -0
- package/src/index.ts +32 -0
- package/src/types.ts +268 -0
- package/tsconfig.json +25 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the agent-memory API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
|
|
5
|
+
* No external dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAgentMemoryClient } from "@aumos/agent-memory";
|
|
10
|
+
*
|
|
11
|
+
* const client = createAgentMemoryClient({ baseUrl: "http://localhost:8060" });
|
|
12
|
+
*
|
|
13
|
+
* // Store a new memory in the semantic layer
|
|
14
|
+
* const stored = await client.store({
|
|
15
|
+
* content: "The Eiffel Tower is located in Paris, France.",
|
|
16
|
+
* layer: "semantic",
|
|
17
|
+
* importance_score: 0.8,
|
|
18
|
+
* source: "document",
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* if (stored.ok) {
|
|
22
|
+
* console.log("Memory stored:", stored.data.memory_id);
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* // Hybrid retrieval across all layers
|
|
26
|
+
* const results = await client.search({ query: "Eiffel Tower", limit: 5 });
|
|
27
|
+
* if (results.ok) {
|
|
28
|
+
* for (const result of results.data) {
|
|
29
|
+
* console.log(`[${result.source}] score=${result.score} — ${result.content}`);
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
import type { ApiResult, CompactResult, ForgetQuery, ForgetResult, KnowledgeGraph, MemoryEntry, RetrievalResult, SearchQuery, StoreRequest } from "./types.js";
|
|
35
|
+
/** Configuration options for the AgentMemoryClient. */
|
|
36
|
+
export interface AgentMemoryClientConfig {
|
|
37
|
+
/** Base URL of the agent-memory server (e.g. "http://localhost:8060"). */
|
|
38
|
+
readonly baseUrl: string;
|
|
39
|
+
/** Optional request timeout in milliseconds (default: 30000). */
|
|
40
|
+
readonly timeoutMs?: number;
|
|
41
|
+
/** Optional extra HTTP headers sent with every request. */
|
|
42
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
43
|
+
}
|
|
44
|
+
/** Typed HTTP client for the agent-memory server. */
|
|
45
|
+
export interface AgentMemoryClient {
|
|
46
|
+
/**
|
|
47
|
+
* Persist a new memory entry in the specified layer.
|
|
48
|
+
*
|
|
49
|
+
* The server assigns a unique memory_id and computes the initial
|
|
50
|
+
* freshness score. Returns the full MemoryEntry as stored.
|
|
51
|
+
*
|
|
52
|
+
* @param request - Content, layer, importance, source, and metadata.
|
|
53
|
+
* @returns The persisted MemoryEntry with server-assigned fields.
|
|
54
|
+
*/
|
|
55
|
+
store(request: StoreRequest): Promise<ApiResult<MemoryEntry>>;
|
|
56
|
+
/**
|
|
57
|
+
* Retrieve a specific memory entry by its ID.
|
|
58
|
+
*
|
|
59
|
+
* Accessing a memory updates its last_accessed timestamp and
|
|
60
|
+
* increments access_count on the server.
|
|
61
|
+
*
|
|
62
|
+
* @param memoryId - The UUID of the memory entry to retrieve.
|
|
63
|
+
* @returns The MemoryEntry if found, or a 404 error result.
|
|
64
|
+
*/
|
|
65
|
+
retrieve(memoryId: string): Promise<ApiResult<MemoryEntry>>;
|
|
66
|
+
/**
|
|
67
|
+
* Perform a hybrid (vector + graph + recency) search across memory layers.
|
|
68
|
+
*
|
|
69
|
+
* Combines semantic similarity, knowledge graph traversal, and recency
|
|
70
|
+
* signals, fusing results into a single ranked list.
|
|
71
|
+
*
|
|
72
|
+
* @param query - Query string, optional layer filter, and result limit.
|
|
73
|
+
* @returns Ranked RetrievalResult array from all active retrieval backends.
|
|
74
|
+
*/
|
|
75
|
+
search(query: SearchQuery): Promise<ApiResult<readonly RetrievalResult[]>>;
|
|
76
|
+
/**
|
|
77
|
+
* Remove one or more memory entries matching the given criteria.
|
|
78
|
+
*
|
|
79
|
+
* When memoryId is provided, only that specific entry is removed.
|
|
80
|
+
* When layer is provided without memoryId, all entries in that layer
|
|
81
|
+
* are removed. When belowImportance is provided, entries with an
|
|
82
|
+
* importance_score below the threshold are candidates for removal.
|
|
83
|
+
*
|
|
84
|
+
* Safety-critical entries are never removed by automated forget calls.
|
|
85
|
+
*
|
|
86
|
+
* @param query - Removal criteria: by ID, layer, or importance threshold.
|
|
87
|
+
* @returns ForgetResult with removed count and IDs.
|
|
88
|
+
*/
|
|
89
|
+
forget(query: ForgetQuery): Promise<ApiResult<ForgetResult>>;
|
|
90
|
+
/**
|
|
91
|
+
* Retrieve the current knowledge graph structure.
|
|
92
|
+
*
|
|
93
|
+
* Returns all nodes and directed edges from the semantic knowledge graph,
|
|
94
|
+
* including node labels, relation types, and edge weights.
|
|
95
|
+
*
|
|
96
|
+
* @returns KnowledgeGraph snapshot with nodes, edges, and counts.
|
|
97
|
+
*/
|
|
98
|
+
getKnowledgeGraph(): Promise<ApiResult<KnowledgeGraph>>;
|
|
99
|
+
/**
|
|
100
|
+
* Trigger a memory compaction pass.
|
|
101
|
+
*
|
|
102
|
+
* Compaction removes stale low-importance entries, merges near-duplicate
|
|
103
|
+
* content, and refreshes freshness scores based on access patterns.
|
|
104
|
+
* The operation runs server-side and returns a summary of changes made.
|
|
105
|
+
*
|
|
106
|
+
* @param options - Optional compaction parameters.
|
|
107
|
+
* @returns CompactResult with before/after counts and duration.
|
|
108
|
+
*/
|
|
109
|
+
compact(options?: {
|
|
110
|
+
layer?: import("./types.js").MemoryLayer;
|
|
111
|
+
importanceThreshold?: number;
|
|
112
|
+
}): Promise<ApiResult<CompactResult>>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a typed HTTP client for the agent-memory server.
|
|
116
|
+
*
|
|
117
|
+
* @param config - Client configuration including base URL.
|
|
118
|
+
* @returns An AgentMemoryClient instance.
|
|
119
|
+
*/
|
|
120
|
+
export declare function createAgentMemoryClient(config: AgentMemoryClientConfig): AgentMemoryClient;
|
|
121
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAEV,SAAS,EACT,aAAa,EACb,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,eAAe,EACf,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAMpB,uDAAuD;AACvD,MAAM,WAAW,uBAAuB;IACtC,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iEAAiE;IACjE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD;AA0DD,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IAE9D;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IAE5D;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,eAAe,EAAE,CAAC,CAAC,CAAC;IAE3E;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;IAE7D;;;;;;;OAOG;IACH,iBAAiB,IAAI,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;IAExD;;;;;;;;;OASG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE;QAChB,KAAK,CAAC,EAAE,OAAO,YAAY,EAAE,WAAW,CAAC;QACzC,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,GAAG,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;CACvC;AAMD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,uBAAuB,GAC9B,iBAAiB,CAuFnB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the agent-memory API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
|
|
5
|
+
* No external dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAgentMemoryClient } from "@aumos/agent-memory";
|
|
10
|
+
*
|
|
11
|
+
* const client = createAgentMemoryClient({ baseUrl: "http://localhost:8060" });
|
|
12
|
+
*
|
|
13
|
+
* // Store a new memory in the semantic layer
|
|
14
|
+
* const stored = await client.store({
|
|
15
|
+
* content: "The Eiffel Tower is located in Paris, France.",
|
|
16
|
+
* layer: "semantic",
|
|
17
|
+
* importance_score: 0.8,
|
|
18
|
+
* source: "document",
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* if (stored.ok) {
|
|
22
|
+
* console.log("Memory stored:", stored.data.memory_id);
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* // Hybrid retrieval across all layers
|
|
26
|
+
* const results = await client.search({ query: "Eiffel Tower", limit: 5 });
|
|
27
|
+
* if (results.ok) {
|
|
28
|
+
* for (const result of results.data) {
|
|
29
|
+
* console.log(`[${result.source}] score=${result.score} — ${result.content}`);
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Internal helpers
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
async function fetchJson(url, init, timeoutMs) {
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
40
|
+
try {
|
|
41
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
const body = await response.json();
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
const errorBody = body;
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
error: {
|
|
49
|
+
error: errorBody.error ?? "Unknown error",
|
|
50
|
+
detail: errorBody.detail ?? "",
|
|
51
|
+
},
|
|
52
|
+
status: response.status,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return { ok: true, data: body };
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
clearTimeout(timeoutId);
|
|
59
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
error: { error: "Network error", detail: message },
|
|
63
|
+
status: 0,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function buildHeaders(extraHeaders) {
|
|
68
|
+
return {
|
|
69
|
+
"Content-Type": "application/json",
|
|
70
|
+
Accept: "application/json",
|
|
71
|
+
...extraHeaders,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Client factory
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
/**
|
|
78
|
+
* Create a typed HTTP client for the agent-memory server.
|
|
79
|
+
*
|
|
80
|
+
* @param config - Client configuration including base URL.
|
|
81
|
+
* @returns An AgentMemoryClient instance.
|
|
82
|
+
*/
|
|
83
|
+
export function createAgentMemoryClient(config) {
|
|
84
|
+
const { baseUrl, timeoutMs = 30_000, headers: extraHeaders } = config;
|
|
85
|
+
const baseHeaders = buildHeaders(extraHeaders);
|
|
86
|
+
return {
|
|
87
|
+
async store(request) {
|
|
88
|
+
return fetchJson(`${baseUrl}/memory`, {
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: baseHeaders,
|
|
91
|
+
body: JSON.stringify(request),
|
|
92
|
+
}, timeoutMs);
|
|
93
|
+
},
|
|
94
|
+
async retrieve(memoryId) {
|
|
95
|
+
return fetchJson(`${baseUrl}/memory/${encodeURIComponent(memoryId)}`, { method: "GET", headers: baseHeaders }, timeoutMs);
|
|
96
|
+
},
|
|
97
|
+
async search(query) {
|
|
98
|
+
const params = new URLSearchParams({ query: query.query });
|
|
99
|
+
if (query.layer !== undefined) {
|
|
100
|
+
params.set("layer", query.layer);
|
|
101
|
+
}
|
|
102
|
+
if (query.limit !== undefined) {
|
|
103
|
+
params.set("limit", String(query.limit));
|
|
104
|
+
}
|
|
105
|
+
return fetchJson(`${baseUrl}/memory/search?${params.toString()}`, { method: "GET", headers: baseHeaders }, timeoutMs);
|
|
106
|
+
},
|
|
107
|
+
async forget(query) {
|
|
108
|
+
return fetchJson(`${baseUrl}/memory/forget`, {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers: baseHeaders,
|
|
111
|
+
body: JSON.stringify({
|
|
112
|
+
memory_id: query.memoryId,
|
|
113
|
+
layer: query.layer,
|
|
114
|
+
below_importance: query.belowImportance,
|
|
115
|
+
}),
|
|
116
|
+
}, timeoutMs);
|
|
117
|
+
},
|
|
118
|
+
async getKnowledgeGraph() {
|
|
119
|
+
return fetchJson(`${baseUrl}/memory/graph`, { method: "GET", headers: baseHeaders }, timeoutMs);
|
|
120
|
+
},
|
|
121
|
+
async compact(options = {}) {
|
|
122
|
+
return fetchJson(`${baseUrl}/memory/compact`, {
|
|
123
|
+
method: "POST",
|
|
124
|
+
headers: baseHeaders,
|
|
125
|
+
body: JSON.stringify({
|
|
126
|
+
layer: options.layer,
|
|
127
|
+
importance_threshold: options.importanceThreshold,
|
|
128
|
+
}),
|
|
129
|
+
}, timeoutMs);
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AA6BH,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,KAAK,UAAU,SAAS,CACtB,GAAW,EACX,IAAiB,EACjB,SAAiB;IAEjB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;IAElE,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1E,YAAY,CAAC,SAAS,CAAC,CAAC;QAExB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAa,CAAC;QAE9C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,IAAyB,CAAC;YAC5C,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE;oBACL,KAAK,EAAE,SA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E,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,EACvC,SAAS,CACV,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,OAAO,CACX,UAGI,EAAE;YAEN,OAAO,SAAS,CACd,GAAG,OAAO,iBAAiB,EAC3B;gBACE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,WAAW;gBACpB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,oBAAoB,EAAE,OAAO,CAAC,mBAAmB;iBAClD,CAAC;aACH,EACD,SAAS,CACV,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aumos/agent-memory
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for the AumOS agent-memory framework.
|
|
5
|
+
* Provides multi-layer memory management, hybrid retrieval,
|
|
6
|
+
* knowledge graph access, and memory compaction.
|
|
7
|
+
*/
|
|
8
|
+
export type { AgentMemoryClient, AgentMemoryClientConfig } from "./client.js";
|
|
9
|
+
export { createAgentMemoryClient } from "./client.js";
|
|
10
|
+
export type { MemoryLayer, MemorySource, ImportanceLevel, MemoryEntry, KnowledgeNode, KnowledgeEdge, KnowledgeGraph, EpisodeRecord, RetrievalQuery, RetrievalResult, CompactResult, StoreRequest, SearchQuery, ForgetQuery, ForgetResult, ApiError, ApiResult, } from "./types.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD,YAAY,EACV,WAAW,EACX,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,EACb,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,aAAa,EACb,YAAY,EACZ,WAAW,EACX,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aumos/agent-memory
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for the AumOS agent-memory framework.
|
|
5
|
+
* Provides multi-layer memory management, hybrid retrieval,
|
|
6
|
+
* knowledge graph access, and memory compaction.
|
|
7
|
+
*/
|
|
8
|
+
export { createAgentMemoryClient } from "./client.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the agent-memory framework.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Pydantic/dataclass models defined in:
|
|
5
|
+
* agent_memory.memory.types — MemoryLayer, MemoryEntry, MemorySource
|
|
6
|
+
* agent_memory.retrieval.graph_retriever — RetrievalResult
|
|
7
|
+
* agent_memory.memory.episodic — EpisodicMemory
|
|
8
|
+
*
|
|
9
|
+
* All interfaces use readonly fields to match Python frozen models.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The four cognitive memory layers supported by the framework.
|
|
13
|
+
* Maps to the MemoryLayer enum in agent_memory.memory.types.
|
|
14
|
+
*
|
|
15
|
+
* - working — short-lived, session-scoped scratchpad memory
|
|
16
|
+
* - episodic — time-ordered event log (what happened, when)
|
|
17
|
+
* - semantic — factual knowledge and learned concepts
|
|
18
|
+
* - procedural — learned skills, workflows, and action templates
|
|
19
|
+
*/
|
|
20
|
+
export type MemoryLayer = "working" | "episodic" | "semantic" | "procedural";
|
|
21
|
+
/**
|
|
22
|
+
* Origin of a memory entry.
|
|
23
|
+
* Maps to the MemorySource enum in agent_memory.memory.types.
|
|
24
|
+
*/
|
|
25
|
+
export type MemorySource = "user_input" | "tool_output" | "agent_inference" | "document" | "external_api";
|
|
26
|
+
/**
|
|
27
|
+
* Qualitative importance tier for a memory entry.
|
|
28
|
+
* Maps to the ImportanceLevel enum in agent_memory.memory.types.
|
|
29
|
+
*/
|
|
30
|
+
export type ImportanceLevel = "critical" | "high" | "medium" | "low" | "trivial";
|
|
31
|
+
/**
|
|
32
|
+
* A single memory record stored across any layer.
|
|
33
|
+
* Maps to MemoryEntry in agent_memory.memory.types.
|
|
34
|
+
*/
|
|
35
|
+
export interface MemoryEntry {
|
|
36
|
+
/** Unique identifier for this memory record (UUID v4). */
|
|
37
|
+
readonly memory_id: string;
|
|
38
|
+
/** The textual content of this memory. */
|
|
39
|
+
readonly content: string;
|
|
40
|
+
/** Which cognitive memory layer this entry belongs to. */
|
|
41
|
+
readonly layer: MemoryLayer;
|
|
42
|
+
/** Numeric importance score in [0, 1]. Higher is more important. */
|
|
43
|
+
readonly importance_score: number;
|
|
44
|
+
/** Numeric freshness score in [0, 1]. Decays over time. */
|
|
45
|
+
readonly freshness_score: number;
|
|
46
|
+
/** Origin of this memory entry. */
|
|
47
|
+
readonly source: MemorySource;
|
|
48
|
+
/** ISO-8601 UTC timestamp when this entry was first created. */
|
|
49
|
+
readonly created_at: string;
|
|
50
|
+
/** ISO-8601 UTC timestamp of the most recent access. */
|
|
51
|
+
readonly last_accessed: string;
|
|
52
|
+
/** Number of times this entry has been retrieved. */
|
|
53
|
+
readonly access_count: number;
|
|
54
|
+
/** When true this entry is protected from automated forgetting. */
|
|
55
|
+
readonly safety_critical: boolean;
|
|
56
|
+
/** Derived composite relevance score: importance_score * freshness_score. */
|
|
57
|
+
readonly composite_score: number;
|
|
58
|
+
/** Qualitative importance tier derived from importance_score. */
|
|
59
|
+
readonly importance_level: ImportanceLevel;
|
|
60
|
+
/** Arbitrary string key/value metadata. */
|
|
61
|
+
readonly metadata: Readonly<Record<string, string>>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A single node in the knowledge graph.
|
|
65
|
+
*/
|
|
66
|
+
export interface KnowledgeNode {
|
|
67
|
+
/** Node label — also serves as the unique identifier within the graph. */
|
|
68
|
+
readonly label: string;
|
|
69
|
+
/** Outgoing edges from this node. */
|
|
70
|
+
readonly edges: readonly KnowledgeEdge[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A directed, weighted edge in the knowledge graph.
|
|
74
|
+
*/
|
|
75
|
+
export interface KnowledgeEdge {
|
|
76
|
+
/** Relation type string (e.g. "capital_of", "knows", "related_to"). */
|
|
77
|
+
readonly relation: string;
|
|
78
|
+
/** Label of the target node. */
|
|
79
|
+
readonly target: string;
|
|
80
|
+
/** Edge weight in (0.0, 1.0]. Higher weight means greater relevance. */
|
|
81
|
+
readonly weight: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Snapshot of the knowledge graph structure.
|
|
85
|
+
*/
|
|
86
|
+
export interface KnowledgeGraph {
|
|
87
|
+
/** Total number of nodes in the graph. */
|
|
88
|
+
readonly node_count: number;
|
|
89
|
+
/** Total number of directed edges in the graph. */
|
|
90
|
+
readonly edge_count: number;
|
|
91
|
+
/** All nodes with their outgoing edges. */
|
|
92
|
+
readonly nodes: readonly KnowledgeNode[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A time-bounded episode record returned from episodic memory queries.
|
|
96
|
+
* Groups temporally adjacent events into a named episode.
|
|
97
|
+
*/
|
|
98
|
+
export interface EpisodeRecord {
|
|
99
|
+
/** Unique identifier for this episode. */
|
|
100
|
+
readonly episode_id: string;
|
|
101
|
+
/** Human-readable title or label for this episode. */
|
|
102
|
+
readonly title: string;
|
|
103
|
+
/** ISO-8601 UTC timestamp when the episode started. */
|
|
104
|
+
readonly started_at: string;
|
|
105
|
+
/** ISO-8601 UTC timestamp when the episode ended (null if ongoing). */
|
|
106
|
+
readonly ended_at: string | null;
|
|
107
|
+
/** Memory entries that make up this episode. */
|
|
108
|
+
readonly entries: readonly MemoryEntry[];
|
|
109
|
+
/** Number of entries in this episode. */
|
|
110
|
+
readonly entry_count: number;
|
|
111
|
+
/** Arbitrary metadata attached to this episode. */
|
|
112
|
+
readonly metadata: Readonly<Record<string, string>>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Query parameters for memory retrieval operations.
|
|
116
|
+
*/
|
|
117
|
+
export interface RetrievalQuery {
|
|
118
|
+
/** Free-text query string used to find relevant memories. */
|
|
119
|
+
readonly query: string;
|
|
120
|
+
/** Restrict retrieval to a specific memory layer (null = all layers). */
|
|
121
|
+
readonly layer?: MemoryLayer;
|
|
122
|
+
/** Maximum number of results to return (default 10). */
|
|
123
|
+
readonly top_k?: number;
|
|
124
|
+
/** Minimum composite score threshold for inclusion (0.0–1.0). */
|
|
125
|
+
readonly min_score?: number;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A single result from a retrieval or search operation.
|
|
129
|
+
* Maps to RetrievalResult in agent_memory.retrieval.graph_retriever.
|
|
130
|
+
*/
|
|
131
|
+
export interface RetrievalResult {
|
|
132
|
+
/** The retrieved text content or node label. */
|
|
133
|
+
readonly content: string;
|
|
134
|
+
/** Which backend produced this result: "vector", "graph", or "recency". */
|
|
135
|
+
readonly source: "vector" | "graph" | "recency";
|
|
136
|
+
/** Relevance score in [0.0, 1.0]. */
|
|
137
|
+
readonly score: number;
|
|
138
|
+
/** Arbitrary metadata from the retrieval backend. */
|
|
139
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Result returned after a memory compaction operation.
|
|
143
|
+
*/
|
|
144
|
+
export interface CompactResult {
|
|
145
|
+
/** Total number of entries before compaction. */
|
|
146
|
+
readonly entries_before: number;
|
|
147
|
+
/** Total number of entries after compaction. */
|
|
148
|
+
readonly entries_after: number;
|
|
149
|
+
/** Number of entries that were removed. */
|
|
150
|
+
readonly entries_removed: number;
|
|
151
|
+
/** Number of entries that were merged or consolidated. */
|
|
152
|
+
readonly entries_merged: number;
|
|
153
|
+
/** Wall-clock milliseconds the compaction took. */
|
|
154
|
+
readonly duration_ms: number;
|
|
155
|
+
/** ISO-8601 UTC timestamp when compaction completed. */
|
|
156
|
+
readonly completed_at: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Request body for the store operation.
|
|
160
|
+
*/
|
|
161
|
+
export interface StoreRequest {
|
|
162
|
+
/** The textual content to store. */
|
|
163
|
+
readonly content: string;
|
|
164
|
+
/** Memory layer to store this entry in. */
|
|
165
|
+
readonly layer: MemoryLayer;
|
|
166
|
+
/** Importance score [0, 1] (default 0.5). */
|
|
167
|
+
readonly importance_score?: number;
|
|
168
|
+
/** Origin of this memory (default "agent_inference"). */
|
|
169
|
+
readonly source?: MemorySource;
|
|
170
|
+
/** Whether this entry is safety-critical (default false). */
|
|
171
|
+
readonly safety_critical?: boolean;
|
|
172
|
+
/** Arbitrary key/value metadata. */
|
|
173
|
+
readonly metadata?: Readonly<Record<string, string>>;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Query parameters for the search endpoint.
|
|
177
|
+
*/
|
|
178
|
+
export interface SearchQuery {
|
|
179
|
+
/** Free-text search string. */
|
|
180
|
+
readonly query: string;
|
|
181
|
+
/** Restrict to a specific layer (omit for all layers). */
|
|
182
|
+
readonly layer?: MemoryLayer;
|
|
183
|
+
/** Maximum number of results (default 10). */
|
|
184
|
+
readonly limit?: number;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Query parameters for the forget endpoint.
|
|
188
|
+
*/
|
|
189
|
+
export interface ForgetQuery {
|
|
190
|
+
/** Specific memory ID to remove (takes precedence over other filters). */
|
|
191
|
+
readonly memoryId?: string;
|
|
192
|
+
/** Remove all entries in this layer. */
|
|
193
|
+
readonly layer?: MemoryLayer;
|
|
194
|
+
/** Remove entries below this importance score threshold. */
|
|
195
|
+
readonly belowImportance?: number;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Response from the forget operation.
|
|
199
|
+
*/
|
|
200
|
+
export interface ForgetResult {
|
|
201
|
+
/** Number of entries removed. */
|
|
202
|
+
readonly removed_count: number;
|
|
203
|
+
/** IDs of the removed entries. */
|
|
204
|
+
readonly removed_ids: readonly string[];
|
|
205
|
+
}
|
|
206
|
+
/** Standard error payload returned by the agent-memory API. */
|
|
207
|
+
export interface ApiError {
|
|
208
|
+
readonly error: string;
|
|
209
|
+
readonly detail: string;
|
|
210
|
+
}
|
|
211
|
+
/** Result type for all client operations. */
|
|
212
|
+
export type ApiResult<T> = {
|
|
213
|
+
readonly ok: true;
|
|
214
|
+
readonly data: T;
|
|
215
|
+
} | {
|
|
216
|
+
readonly ok: false;
|
|
217
|
+
readonly error: ApiError;
|
|
218
|
+
readonly status: number;
|
|
219
|
+
};
|
|
220
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,CAAC;AAE7E;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB,YAAY,GACZ,aAAa,GACb,iBAAiB,GACjB,UAAU,GACV,cAAc,CAAC;AAEnB;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;AAMjF;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,0DAA0D;IA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AAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,wCAAwC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,kCAAkC;IAClC,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAMD,+DAA+D;AAC/D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,6CAA6C;AAC7C,MAAM,MAAM,SAAS,CAAC,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACvC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the agent-memory framework.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Pydantic/dataclass models defined in:
|
|
5
|
+
* agent_memory.memory.types — MemoryLayer, MemoryEntry, MemorySource
|
|
6
|
+
* agent_memory.retrieval.graph_retriever — RetrievalResult
|
|
7
|
+
* agent_memory.memory.episodic — EpisodicMemory
|
|
8
|
+
*
|
|
9
|
+
* All interfaces use readonly fields to match Python frozen models.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aumos/agent-memory",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client for the AumOS agent-memory framework — multi-layer memory management, knowledge graphs, and hybrid retrieval",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.3.0"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"aumos",
|
|
24
|
+
"agent-memory",
|
|
25
|
+
"memory",
|
|
26
|
+
"knowledge-graph",
|
|
27
|
+
"retrieval",
|
|
28
|
+
"episodic-memory",
|
|
29
|
+
"semantic-memory",
|
|
30
|
+
"typescript"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/aumos-ai/agent-memory"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the agent-memory API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
|
|
5
|
+
* No external dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAgentMemoryClient } from "@aumos/agent-memory";
|
|
10
|
+
*
|
|
11
|
+
* const client = createAgentMemoryClient({ baseUrl: "http://localhost:8060" });
|
|
12
|
+
*
|
|
13
|
+
* // Store a new memory in the semantic layer
|
|
14
|
+
* const stored = await client.store({
|
|
15
|
+
* content: "The Eiffel Tower is located in Paris, France.",
|
|
16
|
+
* layer: "semantic",
|
|
17
|
+
* importance_score: 0.8,
|
|
18
|
+
* source: "document",
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* if (stored.ok) {
|
|
22
|
+
* console.log("Memory stored:", stored.data.memory_id);
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* // Hybrid retrieval across all layers
|
|
26
|
+
* const results = await client.search({ query: "Eiffel Tower", limit: 5 });
|
|
27
|
+
* if (results.ok) {
|
|
28
|
+
* for (const result of results.data) {
|
|
29
|
+
* console.log(`[${result.source}] score=${result.score} — ${result.content}`);
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import type {
|
|
36
|
+
ApiError,
|
|
37
|
+
ApiResult,
|
|
38
|
+
CompactResult,
|
|
39
|
+
ForgetQuery,
|
|
40
|
+
ForgetResult,
|
|
41
|
+
KnowledgeGraph,
|
|
42
|
+
MemoryEntry,
|
|
43
|
+
RetrievalResult,
|
|
44
|
+
SearchQuery,
|
|
45
|
+
StoreRequest,
|
|
46
|
+
} from "./types.js";
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Client configuration
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
/** Configuration options for the AgentMemoryClient. */
|
|
53
|
+
export interface AgentMemoryClientConfig {
|
|
54
|
+
/** Base URL of the agent-memory server (e.g. "http://localhost:8060"). */
|
|
55
|
+
readonly baseUrl: string;
|
|
56
|
+
/** Optional request timeout in milliseconds (default: 30000). */
|
|
57
|
+
readonly timeoutMs?: number;
|
|
58
|
+
/** Optional extra HTTP headers sent with every request. */
|
|
59
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Internal helpers
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
async function fetchJson<T>(
|
|
67
|
+
url: string,
|
|
68
|
+
init: RequestInit,
|
|
69
|
+
timeoutMs: number,
|
|
70
|
+
): Promise<ApiResult<T>> {
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
76
|
+
clearTimeout(timeoutId);
|
|
77
|
+
|
|
78
|
+
const body = await response.json() as unknown;
|
|
79
|
+
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
const errorBody = body as Partial<ApiError>;
|
|
82
|
+
return {
|
|
83
|
+
ok: false,
|
|
84
|
+
error: {
|
|
85
|
+
error: errorBody.error ?? "Unknown error",
|
|
86
|
+
detail: errorBody.detail ?? "",
|
|
87
|
+
},
|
|
88
|
+
status: response.status,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { ok: true, data: body as T };
|
|
93
|
+
} catch (err: unknown) {
|
|
94
|
+
clearTimeout(timeoutId);
|
|
95
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
96
|
+
return {
|
|
97
|
+
ok: false,
|
|
98
|
+
error: { error: "Network error", detail: message },
|
|
99
|
+
status: 0,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function buildHeaders(
|
|
105
|
+
extraHeaders: Readonly<Record<string, string>> | undefined,
|
|
106
|
+
): Record<string, string> {
|
|
107
|
+
return {
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
Accept: "application/json",
|
|
110
|
+
...extraHeaders,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
// Client interface
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
/** Typed HTTP client for the agent-memory server. */
|
|
119
|
+
export interface AgentMemoryClient {
|
|
120
|
+
/**
|
|
121
|
+
* Persist a new memory entry in the specified layer.
|
|
122
|
+
*
|
|
123
|
+
* The server assigns a unique memory_id and computes the initial
|
|
124
|
+
* freshness score. Returns the full MemoryEntry as stored.
|
|
125
|
+
*
|
|
126
|
+
* @param request - Content, layer, importance, source, and metadata.
|
|
127
|
+
* @returns The persisted MemoryEntry with server-assigned fields.
|
|
128
|
+
*/
|
|
129
|
+
store(request: StoreRequest): Promise<ApiResult<MemoryEntry>>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Retrieve a specific memory entry by its ID.
|
|
133
|
+
*
|
|
134
|
+
* Accessing a memory updates its last_accessed timestamp and
|
|
135
|
+
* increments access_count on the server.
|
|
136
|
+
*
|
|
137
|
+
* @param memoryId - The UUID of the memory entry to retrieve.
|
|
138
|
+
* @returns The MemoryEntry if found, or a 404 error result.
|
|
139
|
+
*/
|
|
140
|
+
retrieve(memoryId: string): Promise<ApiResult<MemoryEntry>>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Perform a hybrid (vector + graph + recency) search across memory layers.
|
|
144
|
+
*
|
|
145
|
+
* Combines semantic similarity, knowledge graph traversal, and recency
|
|
146
|
+
* signals, fusing results into a single ranked list.
|
|
147
|
+
*
|
|
148
|
+
* @param query - Query string, optional layer filter, and result limit.
|
|
149
|
+
* @returns Ranked RetrievalResult array from all active retrieval backends.
|
|
150
|
+
*/
|
|
151
|
+
search(query: SearchQuery): Promise<ApiResult<readonly RetrievalResult[]>>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Remove one or more memory entries matching the given criteria.
|
|
155
|
+
*
|
|
156
|
+
* When memoryId is provided, only that specific entry is removed.
|
|
157
|
+
* When layer is provided without memoryId, all entries in that layer
|
|
158
|
+
* are removed. When belowImportance is provided, entries with an
|
|
159
|
+
* importance_score below the threshold are candidates for removal.
|
|
160
|
+
*
|
|
161
|
+
* Safety-critical entries are never removed by automated forget calls.
|
|
162
|
+
*
|
|
163
|
+
* @param query - Removal criteria: by ID, layer, or importance threshold.
|
|
164
|
+
* @returns ForgetResult with removed count and IDs.
|
|
165
|
+
*/
|
|
166
|
+
forget(query: ForgetQuery): Promise<ApiResult<ForgetResult>>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Retrieve the current knowledge graph structure.
|
|
170
|
+
*
|
|
171
|
+
* Returns all nodes and directed edges from the semantic knowledge graph,
|
|
172
|
+
* including node labels, relation types, and edge weights.
|
|
173
|
+
*
|
|
174
|
+
* @returns KnowledgeGraph snapshot with nodes, edges, and counts.
|
|
175
|
+
*/
|
|
176
|
+
getKnowledgeGraph(): Promise<ApiResult<KnowledgeGraph>>;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Trigger a memory compaction pass.
|
|
180
|
+
*
|
|
181
|
+
* Compaction removes stale low-importance entries, merges near-duplicate
|
|
182
|
+
* content, and refreshes freshness scores based on access patterns.
|
|
183
|
+
* The operation runs server-side and returns a summary of changes made.
|
|
184
|
+
*
|
|
185
|
+
* @param options - Optional compaction parameters.
|
|
186
|
+
* @returns CompactResult with before/after counts and duration.
|
|
187
|
+
*/
|
|
188
|
+
compact(options?: {
|
|
189
|
+
layer?: import("./types.js").MemoryLayer;
|
|
190
|
+
importanceThreshold?: number;
|
|
191
|
+
}): Promise<ApiResult<CompactResult>>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
// Client factory
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Create a typed HTTP client for the agent-memory server.
|
|
200
|
+
*
|
|
201
|
+
* @param config - Client configuration including base URL.
|
|
202
|
+
* @returns An AgentMemoryClient instance.
|
|
203
|
+
*/
|
|
204
|
+
export function createAgentMemoryClient(
|
|
205
|
+
config: AgentMemoryClientConfig,
|
|
206
|
+
): AgentMemoryClient {
|
|
207
|
+
const { baseUrl, timeoutMs = 30_000, headers: extraHeaders } = config;
|
|
208
|
+
const baseHeaders = buildHeaders(extraHeaders);
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
async store(request: StoreRequest): Promise<ApiResult<MemoryEntry>> {
|
|
212
|
+
return fetchJson<MemoryEntry>(
|
|
213
|
+
`${baseUrl}/memory`,
|
|
214
|
+
{
|
|
215
|
+
method: "POST",
|
|
216
|
+
headers: baseHeaders,
|
|
217
|
+
body: JSON.stringify(request),
|
|
218
|
+
},
|
|
219
|
+
timeoutMs,
|
|
220
|
+
);
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
async retrieve(memoryId: string): Promise<ApiResult<MemoryEntry>> {
|
|
224
|
+
return fetchJson<MemoryEntry>(
|
|
225
|
+
`${baseUrl}/memory/${encodeURIComponent(memoryId)}`,
|
|
226
|
+
{ method: "GET", headers: baseHeaders },
|
|
227
|
+
timeoutMs,
|
|
228
|
+
);
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
async search(
|
|
232
|
+
query: SearchQuery,
|
|
233
|
+
): Promise<ApiResult<readonly RetrievalResult[]>> {
|
|
234
|
+
const params = new URLSearchParams({ query: query.query });
|
|
235
|
+
if (query.layer !== undefined) {
|
|
236
|
+
params.set("layer", query.layer);
|
|
237
|
+
}
|
|
238
|
+
if (query.limit !== undefined) {
|
|
239
|
+
params.set("limit", String(query.limit));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return fetchJson<readonly RetrievalResult[]>(
|
|
243
|
+
`${baseUrl}/memory/search?${params.toString()}`,
|
|
244
|
+
{ method: "GET", headers: baseHeaders },
|
|
245
|
+
timeoutMs,
|
|
246
|
+
);
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
async forget(query: ForgetQuery): Promise<ApiResult<ForgetResult>> {
|
|
250
|
+
return fetchJson<ForgetResult>(
|
|
251
|
+
`${baseUrl}/memory/forget`,
|
|
252
|
+
{
|
|
253
|
+
method: "POST",
|
|
254
|
+
headers: baseHeaders,
|
|
255
|
+
body: JSON.stringify({
|
|
256
|
+
memory_id: query.memoryId,
|
|
257
|
+
layer: query.layer,
|
|
258
|
+
below_importance: query.belowImportance,
|
|
259
|
+
}),
|
|
260
|
+
},
|
|
261
|
+
timeoutMs,
|
|
262
|
+
);
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
async getKnowledgeGraph(): Promise<ApiResult<KnowledgeGraph>> {
|
|
266
|
+
return fetchJson<KnowledgeGraph>(
|
|
267
|
+
`${baseUrl}/memory/graph`,
|
|
268
|
+
{ method: "GET", headers: baseHeaders },
|
|
269
|
+
timeoutMs,
|
|
270
|
+
);
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
async compact(
|
|
274
|
+
options: {
|
|
275
|
+
layer?: import("./types.js").MemoryLayer;
|
|
276
|
+
importanceThreshold?: number;
|
|
277
|
+
} = {},
|
|
278
|
+
): Promise<ApiResult<CompactResult>> {
|
|
279
|
+
return fetchJson<CompactResult>(
|
|
280
|
+
`${baseUrl}/memory/compact`,
|
|
281
|
+
{
|
|
282
|
+
method: "POST",
|
|
283
|
+
headers: baseHeaders,
|
|
284
|
+
body: JSON.stringify({
|
|
285
|
+
layer: options.layer,
|
|
286
|
+
importance_threshold: options.importanceThreshold,
|
|
287
|
+
}),
|
|
288
|
+
},
|
|
289
|
+
timeoutMs,
|
|
290
|
+
);
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aumos/agent-memory
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for the AumOS agent-memory framework.
|
|
5
|
+
* Provides multi-layer memory management, hybrid retrieval,
|
|
6
|
+
* knowledge graph access, and memory compaction.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Client and configuration
|
|
10
|
+
export type { AgentMemoryClient, AgentMemoryClientConfig } from "./client.js";
|
|
11
|
+
export { createAgentMemoryClient } from "./client.js";
|
|
12
|
+
|
|
13
|
+
// Core memory types
|
|
14
|
+
export type {
|
|
15
|
+
MemoryLayer,
|
|
16
|
+
MemorySource,
|
|
17
|
+
ImportanceLevel,
|
|
18
|
+
MemoryEntry,
|
|
19
|
+
KnowledgeNode,
|
|
20
|
+
KnowledgeEdge,
|
|
21
|
+
KnowledgeGraph,
|
|
22
|
+
EpisodeRecord,
|
|
23
|
+
RetrievalQuery,
|
|
24
|
+
RetrievalResult,
|
|
25
|
+
CompactResult,
|
|
26
|
+
StoreRequest,
|
|
27
|
+
SearchQuery,
|
|
28
|
+
ForgetQuery,
|
|
29
|
+
ForgetResult,
|
|
30
|
+
ApiError,
|
|
31
|
+
ApiResult,
|
|
32
|
+
} from "./types.js";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the agent-memory framework.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Pydantic/dataclass models defined in:
|
|
5
|
+
* agent_memory.memory.types — MemoryLayer, MemoryEntry, MemorySource
|
|
6
|
+
* agent_memory.retrieval.graph_retriever — RetrievalResult
|
|
7
|
+
* agent_memory.memory.episodic — EpisodicMemory
|
|
8
|
+
*
|
|
9
|
+
* All interfaces use readonly fields to match Python frozen models.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Memory layer enumerations
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The four cognitive memory layers supported by the framework.
|
|
18
|
+
* Maps to the MemoryLayer enum in agent_memory.memory.types.
|
|
19
|
+
*
|
|
20
|
+
* - working — short-lived, session-scoped scratchpad memory
|
|
21
|
+
* - episodic — time-ordered event log (what happened, when)
|
|
22
|
+
* - semantic — factual knowledge and learned concepts
|
|
23
|
+
* - procedural — learned skills, workflows, and action templates
|
|
24
|
+
*/
|
|
25
|
+
export type MemoryLayer = "working" | "episodic" | "semantic" | "procedural";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Origin of a memory entry.
|
|
29
|
+
* Maps to the MemorySource enum in agent_memory.memory.types.
|
|
30
|
+
*/
|
|
31
|
+
export type MemorySource =
|
|
32
|
+
| "user_input"
|
|
33
|
+
| "tool_output"
|
|
34
|
+
| "agent_inference"
|
|
35
|
+
| "document"
|
|
36
|
+
| "external_api";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Qualitative importance tier for a memory entry.
|
|
40
|
+
* Maps to the ImportanceLevel enum in agent_memory.memory.types.
|
|
41
|
+
*/
|
|
42
|
+
export type ImportanceLevel = "critical" | "high" | "medium" | "low" | "trivial";
|
|
43
|
+
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Core memory entry
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A single memory record stored across any layer.
|
|
50
|
+
* Maps to MemoryEntry in agent_memory.memory.types.
|
|
51
|
+
*/
|
|
52
|
+
export interface MemoryEntry {
|
|
53
|
+
/** Unique identifier for this memory record (UUID v4). */
|
|
54
|
+
readonly memory_id: string;
|
|
55
|
+
/** The textual content of this memory. */
|
|
56
|
+
readonly content: string;
|
|
57
|
+
/** Which cognitive memory layer this entry belongs to. */
|
|
58
|
+
readonly layer: MemoryLayer;
|
|
59
|
+
/** Numeric importance score in [0, 1]. Higher is more important. */
|
|
60
|
+
readonly importance_score: number;
|
|
61
|
+
/** Numeric freshness score in [0, 1]. Decays over time. */
|
|
62
|
+
readonly freshness_score: number;
|
|
63
|
+
/** Origin of this memory entry. */
|
|
64
|
+
readonly source: MemorySource;
|
|
65
|
+
/** ISO-8601 UTC timestamp when this entry was first created. */
|
|
66
|
+
readonly created_at: string;
|
|
67
|
+
/** ISO-8601 UTC timestamp of the most recent access. */
|
|
68
|
+
readonly last_accessed: string;
|
|
69
|
+
/** Number of times this entry has been retrieved. */
|
|
70
|
+
readonly access_count: number;
|
|
71
|
+
/** When true this entry is protected from automated forgetting. */
|
|
72
|
+
readonly safety_critical: boolean;
|
|
73
|
+
/** Derived composite relevance score: importance_score * freshness_score. */
|
|
74
|
+
readonly composite_score: number;
|
|
75
|
+
/** Qualitative importance tier derived from importance_score. */
|
|
76
|
+
readonly importance_level: ImportanceLevel;
|
|
77
|
+
/** Arbitrary string key/value metadata. */
|
|
78
|
+
readonly metadata: Readonly<Record<string, string>>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// Knowledge graph types
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A single node in the knowledge graph.
|
|
87
|
+
*/
|
|
88
|
+
export interface KnowledgeNode {
|
|
89
|
+
/** Node label — also serves as the unique identifier within the graph. */
|
|
90
|
+
readonly label: string;
|
|
91
|
+
/** Outgoing edges from this node. */
|
|
92
|
+
readonly edges: readonly KnowledgeEdge[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A directed, weighted edge in the knowledge graph.
|
|
97
|
+
*/
|
|
98
|
+
export interface KnowledgeEdge {
|
|
99
|
+
/** Relation type string (e.g. "capital_of", "knows", "related_to"). */
|
|
100
|
+
readonly relation: string;
|
|
101
|
+
/** Label of the target node. */
|
|
102
|
+
readonly target: string;
|
|
103
|
+
/** Edge weight in (0.0, 1.0]. Higher weight means greater relevance. */
|
|
104
|
+
readonly weight: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Snapshot of the knowledge graph structure.
|
|
109
|
+
*/
|
|
110
|
+
export interface KnowledgeGraph {
|
|
111
|
+
/** Total number of nodes in the graph. */
|
|
112
|
+
readonly node_count: number;
|
|
113
|
+
/** Total number of directed edges in the graph. */
|
|
114
|
+
readonly edge_count: number;
|
|
115
|
+
/** All nodes with their outgoing edges. */
|
|
116
|
+
readonly nodes: readonly KnowledgeNode[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// Episode record
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A time-bounded episode record returned from episodic memory queries.
|
|
125
|
+
* Groups temporally adjacent events into a named episode.
|
|
126
|
+
*/
|
|
127
|
+
export interface EpisodeRecord {
|
|
128
|
+
/** Unique identifier for this episode. */
|
|
129
|
+
readonly episode_id: string;
|
|
130
|
+
/** Human-readable title or label for this episode. */
|
|
131
|
+
readonly title: string;
|
|
132
|
+
/** ISO-8601 UTC timestamp when the episode started. */
|
|
133
|
+
readonly started_at: string;
|
|
134
|
+
/** ISO-8601 UTC timestamp when the episode ended (null if ongoing). */
|
|
135
|
+
readonly ended_at: string | null;
|
|
136
|
+
/** Memory entries that make up this episode. */
|
|
137
|
+
readonly entries: readonly MemoryEntry[];
|
|
138
|
+
/** Number of entries in this episode. */
|
|
139
|
+
readonly entry_count: number;
|
|
140
|
+
/** Arbitrary metadata attached to this episode. */
|
|
141
|
+
readonly metadata: Readonly<Record<string, string>>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
// Retrieval types
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Query parameters for memory retrieval operations.
|
|
150
|
+
*/
|
|
151
|
+
export interface RetrievalQuery {
|
|
152
|
+
/** Free-text query string used to find relevant memories. */
|
|
153
|
+
readonly query: string;
|
|
154
|
+
/** Restrict retrieval to a specific memory layer (null = all layers). */
|
|
155
|
+
readonly layer?: MemoryLayer;
|
|
156
|
+
/** Maximum number of results to return (default 10). */
|
|
157
|
+
readonly top_k?: number;
|
|
158
|
+
/** Minimum composite score threshold for inclusion (0.0–1.0). */
|
|
159
|
+
readonly min_score?: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* A single result from a retrieval or search operation.
|
|
164
|
+
* Maps to RetrievalResult in agent_memory.retrieval.graph_retriever.
|
|
165
|
+
*/
|
|
166
|
+
export interface RetrievalResult {
|
|
167
|
+
/** The retrieved text content or node label. */
|
|
168
|
+
readonly content: string;
|
|
169
|
+
/** Which backend produced this result: "vector", "graph", or "recency". */
|
|
170
|
+
readonly source: "vector" | "graph" | "recency";
|
|
171
|
+
/** Relevance score in [0.0, 1.0]. */
|
|
172
|
+
readonly score: number;
|
|
173
|
+
/** Arbitrary metadata from the retrieval backend. */
|
|
174
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
// Compact operation result
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Result returned after a memory compaction operation.
|
|
183
|
+
*/
|
|
184
|
+
export interface CompactResult {
|
|
185
|
+
/** Total number of entries before compaction. */
|
|
186
|
+
readonly entries_before: number;
|
|
187
|
+
/** Total number of entries after compaction. */
|
|
188
|
+
readonly entries_after: number;
|
|
189
|
+
/** Number of entries that were removed. */
|
|
190
|
+
readonly entries_removed: number;
|
|
191
|
+
/** Number of entries that were merged or consolidated. */
|
|
192
|
+
readonly entries_merged: number;
|
|
193
|
+
/** Wall-clock milliseconds the compaction took. */
|
|
194
|
+
readonly duration_ms: number;
|
|
195
|
+
/** ISO-8601 UTC timestamp when compaction completed. */
|
|
196
|
+
readonly completed_at: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ---------------------------------------------------------------------------
|
|
200
|
+
// Request/response payload types
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Request body for the store operation.
|
|
205
|
+
*/
|
|
206
|
+
export interface StoreRequest {
|
|
207
|
+
/** The textual content to store. */
|
|
208
|
+
readonly content: string;
|
|
209
|
+
/** Memory layer to store this entry in. */
|
|
210
|
+
readonly layer: MemoryLayer;
|
|
211
|
+
/** Importance score [0, 1] (default 0.5). */
|
|
212
|
+
readonly importance_score?: number;
|
|
213
|
+
/** Origin of this memory (default "agent_inference"). */
|
|
214
|
+
readonly source?: MemorySource;
|
|
215
|
+
/** Whether this entry is safety-critical (default false). */
|
|
216
|
+
readonly safety_critical?: boolean;
|
|
217
|
+
/** Arbitrary key/value metadata. */
|
|
218
|
+
readonly metadata?: Readonly<Record<string, string>>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Query parameters for the search endpoint.
|
|
223
|
+
*/
|
|
224
|
+
export interface SearchQuery {
|
|
225
|
+
/** Free-text search string. */
|
|
226
|
+
readonly query: string;
|
|
227
|
+
/** Restrict to a specific layer (omit for all layers). */
|
|
228
|
+
readonly layer?: MemoryLayer;
|
|
229
|
+
/** Maximum number of results (default 10). */
|
|
230
|
+
readonly limit?: number;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Query parameters for the forget endpoint.
|
|
235
|
+
*/
|
|
236
|
+
export interface ForgetQuery {
|
|
237
|
+
/** Specific memory ID to remove (takes precedence over other filters). */
|
|
238
|
+
readonly memoryId?: string;
|
|
239
|
+
/** Remove all entries in this layer. */
|
|
240
|
+
readonly layer?: MemoryLayer;
|
|
241
|
+
/** Remove entries below this importance score threshold. */
|
|
242
|
+
readonly belowImportance?: number;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Response from the forget operation.
|
|
247
|
+
*/
|
|
248
|
+
export interface ForgetResult {
|
|
249
|
+
/** Number of entries removed. */
|
|
250
|
+
readonly removed_count: number;
|
|
251
|
+
/** IDs of the removed entries. */
|
|
252
|
+
readonly removed_ids: readonly string[];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ---------------------------------------------------------------------------
|
|
256
|
+
// API result wrapper (shared pattern)
|
|
257
|
+
// ---------------------------------------------------------------------------
|
|
258
|
+
|
|
259
|
+
/** Standard error payload returned by the agent-memory API. */
|
|
260
|
+
export interface ApiError {
|
|
261
|
+
readonly error: string;
|
|
262
|
+
readonly detail: string;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Result type for all client operations. */
|
|
266
|
+
export type ApiResult<T> =
|
|
267
|
+
| { readonly ok: true; readonly data: T }
|
|
268
|
+
| { readonly ok: false; readonly error: ApiError; readonly status: number };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM"],
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noImplicitAny": true,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noImplicitReturns": true,
|
|
18
|
+
"exactOptionalPropertyTypes": true,
|
|
19
|
+
"forceConsistentCasingInFileNames": true,
|
|
20
|
+
"esModuleInterop": true,
|
|
21
|
+
"skipLibCheck": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*"],
|
|
24
|
+
"exclude": ["node_modules", "dist"]
|
|
25
|
+
}
|