@prometheus-ai/memory 0.5.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/README.md +107 -0
- package/dist/types/cli.d.ts +35 -0
- package/dist/types/config.d.ts +77 -0
- package/dist/types/core/aaak.d.ts +55 -0
- package/dist/types/core/annotations.d.ts +75 -0
- package/dist/types/core/banks.d.ts +33 -0
- package/dist/types/core/beam/consolidate.d.ts +32 -0
- package/dist/types/core/beam/helpers.d.ts +76 -0
- package/dist/types/core/beam/index.d.ts +59 -0
- package/dist/types/core/beam/recall.d.ts +32 -0
- package/dist/types/core/beam/schema.d.ts +2 -0
- package/dist/types/core/beam/store.d.ts +35 -0
- package/dist/types/core/beam/types.d.ts +233 -0
- package/dist/types/core/binary-vectors.d.ts +54 -0
- package/dist/types/core/chat-normalize.d.ts +13 -0
- package/dist/types/core/content-sanitizer.d.ts +18 -0
- package/dist/types/core/cost-log.d.ts +13 -0
- package/dist/types/core/embeddings.d.ts +44 -0
- package/dist/types/core/entities.d.ts +7 -0
- package/dist/types/core/episodic-graph.d.ts +89 -0
- package/dist/types/core/extraction/client.d.ts +31 -0
- package/dist/types/core/extraction/diagnostics.d.ts +51 -0
- package/dist/types/core/extraction/prompts.d.ts +2 -0
- package/dist/types/core/extraction.d.ts +6 -0
- package/dist/types/core/index.d.ts +4 -0
- package/dist/types/core/llm-backends.d.ts +21 -0
- package/dist/types/core/local-llm.d.ts +15 -0
- package/dist/types/core/memory.d.ts +160 -0
- package/dist/types/core/migrations/e6-triplestore-split.d.ts +17 -0
- package/dist/types/core/migrations/index.d.ts +1 -0
- package/dist/types/core/mmr.d.ts +8 -0
- package/dist/types/core/orchestrator.d.ts +20 -0
- package/dist/types/core/patterns.d.ts +61 -0
- package/dist/types/core/plugins.d.ts +109 -0
- package/dist/types/core/polyphonic-recall.d.ts +66 -0
- package/dist/types/core/query-cache.d.ts +46 -0
- package/dist/types/core/query-intent.d.ts +20 -0
- package/dist/types/core/recall-diagnostics.d.ts +48 -0
- package/dist/types/core/runtime-options.d.ts +68 -0
- package/dist/types/core/shmr.d.ts +56 -0
- package/dist/types/core/streaming.d.ts +136 -0
- package/dist/types/core/synonyms.d.ts +46 -0
- package/dist/types/core/temporal-parser.d.ts +16 -0
- package/dist/types/core/token-counter.d.ts +8 -0
- package/dist/types/core/triples.d.ts +63 -0
- package/dist/types/core/typed-memory.d.ts +39 -0
- package/dist/types/core/vector-math.d.ts +1 -0
- package/dist/types/core/veracity-consolidation.d.ts +60 -0
- package/dist/types/core/weibull.d.ts +96 -0
- package/dist/types/db.d.ts +16 -0
- package/dist/types/diagnose.d.ts +24 -0
- package/dist/types/dr/index.d.ts +1 -0
- package/dist/types/dr/recovery.d.ts +68 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/mcp-server.d.ts +40 -0
- package/dist/types/mcp-tools.d.ts +484 -0
- package/dist/types/migrations/e6-triplestore-split.d.ts +1 -0
- package/dist/types/migrations/index.d.ts +1 -0
- package/dist/types/types.d.ts +145 -0
- package/dist/types/util/datetime.d.ts +8 -0
- package/dist/types/util/env.d.ts +10 -0
- package/dist/types/util/ids.d.ts +3 -0
- package/dist/types/util/lru.d.ts +12 -0
- package/dist/types/util/regex.d.ts +10 -0
- package/package.json +85 -0
- package/src/cli.ts +398 -0
- package/src/config.ts +326 -0
- package/src/core/aaak.ts +142 -0
- package/src/core/annotations.ts +457 -0
- package/src/core/banks.ts +133 -0
- package/src/core/beam/consolidate.ts +965 -0
- package/src/core/beam/helpers.ts +977 -0
- package/src/core/beam/index.ts +353 -0
- package/src/core/beam/recall.ts +1100 -0
- package/src/core/beam/schema.ts +423 -0
- package/src/core/beam/store.ts +829 -0
- package/src/core/beam/types.ts +268 -0
- package/src/core/binary-vectors.ts +317 -0
- package/src/core/chat-normalize.ts +160 -0
- package/src/core/content-sanitizer.ts +136 -0
- package/src/core/cost-log.ts +103 -0
- package/src/core/embeddings.ts +423 -0
- package/src/core/entities.ts +259 -0
- package/src/core/episodic-graph.ts +708 -0
- package/src/core/extraction/client.ts +162 -0
- package/src/core/extraction/diagnostics.ts +193 -0
- package/src/core/extraction/prompts.ts +31 -0
- package/src/core/extraction.ts +335 -0
- package/src/core/index.ts +30 -0
- package/src/core/llm-backends.ts +51 -0
- package/src/core/local-llm.ts +436 -0
- package/src/core/memory.ts +630 -0
- package/src/core/migrations/e6-triplestore-split.ts +211 -0
- package/src/core/migrations/index.ts +1 -0
- package/src/core/mmr.ts +71 -0
- package/src/core/orchestrator.ts +62 -0
- package/src/core/patterns.ts +484 -0
- package/src/core/plugins.ts +375 -0
- package/src/core/polyphonic-recall.ts +563 -0
- package/src/core/query-cache.ts +354 -0
- package/src/core/query-intent.ts +139 -0
- package/src/core/recall-diagnostics.ts +157 -0
- package/src/core/runtime-options.ts +119 -0
- package/src/core/shmr.ts +460 -0
- package/src/core/streaming.ts +419 -0
- package/src/core/synonyms.ts +197 -0
- package/src/core/temporal-parser.ts +363 -0
- package/src/core/token-counter.ts +30 -0
- package/src/core/triples.ts +454 -0
- package/src/core/typed-memory.ts +407 -0
- package/src/core/vector-math.ts +23 -0
- package/src/core/veracity-consolidation.ts +477 -0
- package/src/core/weibull.ts +124 -0
- package/src/db.ts +128 -0
- package/src/diagnose.ts +174 -0
- package/src/dr/index.ts +1 -0
- package/src/dr/recovery.ts +405 -0
- package/src/index.ts +33 -0
- package/src/mcp-server.ts +155 -0
- package/src/mcp-tools.ts +970 -0
- package/src/migrations/e6-triplestore-split.ts +1 -0
- package/src/migrations/index.ts +1 -0
- package/src/types.ts +157 -0
- package/src/util/datetime.ts +69 -0
- package/src/util/env.ts +65 -0
- package/src/util/ids.ts +19 -0
- package/src/util/lru.ts +48 -0
- package/src/util/regex.ts +165 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * from "./core/beam/index";
|
|
2
|
+
export * from "./core/embeddings";
|
|
3
|
+
export * from "./core/llm-backends";
|
|
4
|
+
export * from "./core/memory";
|
|
5
|
+
export {
|
|
6
|
+
addMemory,
|
|
7
|
+
flushExtractions,
|
|
8
|
+
forget,
|
|
9
|
+
get,
|
|
10
|
+
getBank,
|
|
11
|
+
getContext,
|
|
12
|
+
getDefaultInstance,
|
|
13
|
+
getStats,
|
|
14
|
+
Mnemopi,
|
|
15
|
+
Mnemopi as PrometheusMemory,
|
|
16
|
+
query,
|
|
17
|
+
recall,
|
|
18
|
+
recallEnhanced,
|
|
19
|
+
remember,
|
|
20
|
+
resetDefaultInstanceForTests,
|
|
21
|
+
resetMemoryForTests,
|
|
22
|
+
resetModuleStateForTests,
|
|
23
|
+
saveMemory,
|
|
24
|
+
scratchpadClear,
|
|
25
|
+
scratchpadRead,
|
|
26
|
+
scratchpadWrite,
|
|
27
|
+
search,
|
|
28
|
+
setBank,
|
|
29
|
+
sleep,
|
|
30
|
+
sleepAllSessions,
|
|
31
|
+
storeMemory,
|
|
32
|
+
update,
|
|
33
|
+
} from "./core/memory";
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { getToolDefinitions, handleToolCall, type ToolArguments, type ToolDefinition } from "./mcp-tools";
|
|
2
|
+
|
|
3
|
+
export interface JsonRpcRequest {
|
|
4
|
+
readonly jsonrpc?: string;
|
|
5
|
+
readonly id?: string | number | null;
|
|
6
|
+
readonly method?: string;
|
|
7
|
+
readonly params?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface JsonRpcResponse {
|
|
11
|
+
readonly jsonrpc: "2.0";
|
|
12
|
+
readonly id: string | number | null;
|
|
13
|
+
readonly result?: unknown;
|
|
14
|
+
readonly error?: { readonly code: number; readonly message: string };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ListToolsResponse {
|
|
18
|
+
readonly tools: readonly ToolDefinition[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CallToolContent {
|
|
22
|
+
readonly type: "text";
|
|
23
|
+
readonly text: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CallToolResponse {
|
|
27
|
+
readonly content: readonly CallToolContent[];
|
|
28
|
+
readonly isError?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface WritableOutput {
|
|
32
|
+
write(chunk: string): unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ok(id: string | number | null, result: unknown): JsonRpcResponse {
|
|
36
|
+
return { jsonrpc: "2.0", id, result };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function err(id: string | number | null, code: number, message: string): JsonRpcResponse {
|
|
40
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function requestId(request: JsonRpcRequest): string | number | null {
|
|
44
|
+
return typeof request.id === "string" || typeof request.id === "number" || request.id === null ? request.id : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function hasRequestId(request: JsonRpcRequest): boolean {
|
|
48
|
+
return Object.hasOwn(request, "id");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function listToolsJson(): ListToolsResponse {
|
|
52
|
+
return { tools: getToolDefinitions() };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function callToolJson(name: string, args: ToolArguments = {}): Promise<CallToolResponse> {
|
|
56
|
+
try {
|
|
57
|
+
const result = await handleToolCall(name, args);
|
|
58
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
59
|
+
} catch (error) {
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
return {
|
|
62
|
+
content: [{ type: "text", text: JSON.stringify({ status: "error", message }, null, 2) }],
|
|
63
|
+
isError: true,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function handleJsonRpc(request: JsonRpcRequest): Promise<JsonRpcResponse | null> {
|
|
69
|
+
const method = request.method ?? "";
|
|
70
|
+
if (method.startsWith("notifications/") || !hasRequestId(request)) return null;
|
|
71
|
+
const id = requestId(request);
|
|
72
|
+
if (method === "initialize") {
|
|
73
|
+
return ok(id, {
|
|
74
|
+
protocolVersion: "2024-11-05",
|
|
75
|
+
serverInfo: { name: "prometheus-memory", version: "3.1.2" },
|
|
76
|
+
capabilities: { tools: {} },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (method === "tools/list") return ok(id, listToolsJson());
|
|
80
|
+
if (method === "tools/call") {
|
|
81
|
+
const params = request.params ?? {};
|
|
82
|
+
const name = typeof params.name === "string" ? params.name : "";
|
|
83
|
+
const args =
|
|
84
|
+
params.arguments !== null && typeof params.arguments === "object" && !Array.isArray(params.arguments)
|
|
85
|
+
? (params.arguments as ToolArguments)
|
|
86
|
+
: {};
|
|
87
|
+
if (name.length === 0) return err(id, -32602, "tools/call requires params.name");
|
|
88
|
+
return ok(id, await callToolJson(name, args));
|
|
89
|
+
}
|
|
90
|
+
return err(id, -32601, `Unknown method: ${method}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function runStdio(
|
|
94
|
+
input: ReadableStream<Uint8Array> = Bun.stdin.stream(),
|
|
95
|
+
output: WritableOutput = Bun.stdout,
|
|
96
|
+
): Promise<void> {
|
|
97
|
+
const reader = input.getReader();
|
|
98
|
+
const decoder = new TextDecoder();
|
|
99
|
+
let buffer = "";
|
|
100
|
+
try {
|
|
101
|
+
while (true) {
|
|
102
|
+
const chunk = await reader.read();
|
|
103
|
+
if (chunk.done) break;
|
|
104
|
+
buffer += decoder.decode(chunk.value, { stream: true });
|
|
105
|
+
let newline = buffer.indexOf("\n");
|
|
106
|
+
while (newline >= 0) {
|
|
107
|
+
const line = buffer.slice(0, newline).trim();
|
|
108
|
+
buffer = buffer.slice(newline + 1);
|
|
109
|
+
if (line.length > 0) {
|
|
110
|
+
let parsed: unknown;
|
|
111
|
+
try {
|
|
112
|
+
parsed = JSON.parse(line);
|
|
113
|
+
} catch {
|
|
114
|
+
output.write(`${JSON.stringify(err(null, -32700, "Parse error"))}\n`);
|
|
115
|
+
newline = buffer.indexOf("\n");
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const response = await handleJsonRpc(parsed as JsonRpcRequest);
|
|
119
|
+
if (response !== null) output.write(`${JSON.stringify(response)}\n`);
|
|
120
|
+
}
|
|
121
|
+
newline = buffer.indexOf("\n");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} finally {
|
|
125
|
+
reader.releaseLock();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function runMcpServer(
|
|
130
|
+
transport = "stdio",
|
|
131
|
+
options: { port?: number; bank?: string; host?: string } = {},
|
|
132
|
+
): Promise<void> {
|
|
133
|
+
if (options.bank !== undefined && options.bank.length > 0) process.env.PROMETHEUS_MEMORY_MCP_BANK = options.bank;
|
|
134
|
+
if (transport !== "stdio") throw new Error("Only stdio transport is implemented in the TypeScript port");
|
|
135
|
+
return runStdio();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function main(argv: readonly string[] = Bun.argv.slice(2)): Promise<void> {
|
|
139
|
+
let transport = "stdio";
|
|
140
|
+
let port: number | undefined;
|
|
141
|
+
let bank: string | undefined;
|
|
142
|
+
let host: string | undefined;
|
|
143
|
+
for (let i = 0; i < argv.length; i++) {
|
|
144
|
+
const arg = argv[i];
|
|
145
|
+
if (arg === "--transport") transport = argv[++i] ?? "stdio";
|
|
146
|
+
else if (arg === "--port") {
|
|
147
|
+
const parsed = Number(argv[++i] ?? "");
|
|
148
|
+
if (Number.isFinite(parsed)) port = parsed;
|
|
149
|
+
} else if (arg === "--bank") bank = argv[++i] ?? "";
|
|
150
|
+
else if (arg === "--host") host = argv[++i] ?? "";
|
|
151
|
+
}
|
|
152
|
+
return runMcpServer(transport, { port, bank, host });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (import.meta.main) await main();
|