@synapcores/openclaw-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/LICENSE +21 -0
- package/README.md +214 -0
- package/dist/config.d.ts +104 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +165 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +241 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +977 -0
- package/dist/index.js.map +1 -0
- package/openclaw.plugin.json +128 -0
- package/package.json +82 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw Memory (SynapCores) Plugin
|
|
3
|
+
*
|
|
4
|
+
* Long-term memory with vector search for AI conversations.
|
|
5
|
+
* Uses SynapCores AIDB for storage and OpenAI for embeddings.
|
|
6
|
+
* Provides seamless auto-recall and auto-capture via lifecycle hooks,
|
|
7
|
+
* plus three SynapCores-only extensions (SQL-filtered recall, graph-relation
|
|
8
|
+
* walks, and AutoML relevance scoring) — see `recallFiltered`,
|
|
9
|
+
* `recallRelated`, and `predictRelevance`.
|
|
10
|
+
*
|
|
11
|
+
* This is the @synapcores/openclaw-memory drop-in alternative to
|
|
12
|
+
* @openclaw/memory-lancedb. The parity API (recall + capture +
|
|
13
|
+
* auto-recall/auto-capture) plus the three SynapCores-only extensions
|
|
14
|
+
* are all fully wired in 0.1.0.
|
|
15
|
+
*/
|
|
16
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
17
|
+
import { type MemoryCategory } from "./config.js";
|
|
18
|
+
export type MemoryEntry = {
|
|
19
|
+
id: string;
|
|
20
|
+
text: string;
|
|
21
|
+
vector: number[];
|
|
22
|
+
importance: number;
|
|
23
|
+
category: MemoryCategory;
|
|
24
|
+
createdAt: number;
|
|
25
|
+
};
|
|
26
|
+
export type MemorySearchResult = {
|
|
27
|
+
entry: MemoryEntry;
|
|
28
|
+
score: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Options for `recallFiltered`: a SynapCores-only extension that pairs a
|
|
32
|
+
* semantic vector search with a SQL `WHERE` clause (date ranges, tags,
|
|
33
|
+
* importance thresholds, category equality, etc.).
|
|
34
|
+
*/
|
|
35
|
+
export type RecallFilteredOptions = {
|
|
36
|
+
/** SQL fragment applied as the search filter (e.g. `category = 'preference' AND importance >= 0.7`). */
|
|
37
|
+
where: string;
|
|
38
|
+
/** Natural-language query that gets embedded and used as the search vector. */
|
|
39
|
+
semantic: string;
|
|
40
|
+
/** Maximum results to return (default: 5). */
|
|
41
|
+
limit?: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Options for `recallRelated`: a SynapCores-only extension that walks the
|
|
45
|
+
* memory graph from a given memory ID and returns the neighborhood.
|
|
46
|
+
*/
|
|
47
|
+
export type RecallRelatedOptions = {
|
|
48
|
+
/** Maximum graph hops to traverse (default: 1). */
|
|
49
|
+
hops?: number;
|
|
50
|
+
/** Restrict to specific edge kinds (default: any). Common kinds: `SIMILAR_TO`, `MENTIONS`, `RELATES_TO`. */
|
|
51
|
+
edgeKinds?: string[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* One result returned from `recallRelated` — the neighbor memory plus the
|
|
55
|
+
* shortest path length (hops) from the source memory.
|
|
56
|
+
*/
|
|
57
|
+
export type RelatedMemoryResult = {
|
|
58
|
+
entry: MemoryEntry;
|
|
59
|
+
hops: number;
|
|
60
|
+
via: string[];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* One result returned from `predictRelevance` — the candidate memory plus
|
|
64
|
+
* a model-predicted relevance score in [0, 1].
|
|
65
|
+
*/
|
|
66
|
+
export type RelevanceScoredMemory = {
|
|
67
|
+
entry: MemoryEntry;
|
|
68
|
+
/** Predicted relevance score in [0, 1]. */
|
|
69
|
+
relevance: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* One labelled training sample for `trainRelevanceModel`.
|
|
73
|
+
*/
|
|
74
|
+
export type RelevanceFeedback = {
|
|
75
|
+
/** UUID of the memory the user actually engaged with (or didn't). */
|
|
76
|
+
memoryId: string;
|
|
77
|
+
/** Natural-language query the user issued. */
|
|
78
|
+
queryText: string;
|
|
79
|
+
/** Engagement score in [0, 1] (1 = highly relevant, 0 = not relevant). */
|
|
80
|
+
score: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Escape a string literal for safe inlining into a Cypher query.
|
|
84
|
+
*
|
|
85
|
+
* Gateway v1.6.5.2-ce explicitly rejects named-parameter bindings (`$param`)
|
|
86
|
+
* with HTTP 400; the supported path is to inline literal values into the
|
|
87
|
+
* query string. Memory IDs flow in from `randomUUID()` so they are normally
|
|
88
|
+
* safe, BUT we never trust upstream input — every string that ends up
|
|
89
|
+
* inside `'...'` in a Cypher fragment must go through this helper.
|
|
90
|
+
*
|
|
91
|
+
* Escapes single quotes (`'` -> `\'`) and backslashes (`\` -> `\\`).
|
|
92
|
+
* Returns the inner content only; callers are responsible for the
|
|
93
|
+
* surrounding quotes (so the helper is composable with template literals).
|
|
94
|
+
*/
|
|
95
|
+
export declare function escapeCypherString(value: string): string;
|
|
96
|
+
/**
|
|
97
|
+
* Build the runtime extension surface exposed on the plugin instance. These
|
|
98
|
+
* methods are exported via `memoryPlugin.extensions` so callers can reach
|
|
99
|
+
* them through the OpenClaw plugin registry.
|
|
100
|
+
*
|
|
101
|
+
* The three SynapCores-only methods use:
|
|
102
|
+
* - `client.collection(...).vectorSearch({ ..., filter })` for recallFiltered,
|
|
103
|
+
* forwarding the SQL `WHERE` clause through to the gateway under
|
|
104
|
+
* `filter: { sql: where }`.
|
|
105
|
+
* - `client.graph.cypher(...)` for recallRelated, walking the `SIMILAR_TO`
|
|
106
|
+
* edges created automatically at capture-time (plus any `MENTIONS` /
|
|
107
|
+
* `RELATES_TO` edges added by future entity-extraction tools).
|
|
108
|
+
* - `client.automl.getModel(...).predict(...)` for predictRelevance, with
|
|
109
|
+
* a deterministic heuristic fallback when no model is trained yet.
|
|
110
|
+
*/
|
|
111
|
+
export interface MemorySynapCoresExtensions {
|
|
112
|
+
/**
|
|
113
|
+
* Vector recall scoped by a SQL `WHERE` clause.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* await ext.recallFiltered({
|
|
117
|
+
* where: "category = 'preference' AND importance >= 0.7 AND createdAt > 1700000000000",
|
|
118
|
+
* semantic: "what kind of UI does the user prefer?",
|
|
119
|
+
* limit: 5,
|
|
120
|
+
* });
|
|
121
|
+
*/
|
|
122
|
+
recallFiltered(options: RecallFilteredOptions): Promise<MemorySearchResult[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Graph walk from a memory through `SIMILAR_TO` / `MENTIONS` / `RELATES_TO`
|
|
125
|
+
* edges, returning the neighborhood.
|
|
126
|
+
*
|
|
127
|
+
* @param memoryId - UUID of the source memory.
|
|
128
|
+
* @param options - Hops and edge-kind filter.
|
|
129
|
+
*
|
|
130
|
+
* @remarks `SIMILAR_TO` edges are auto-created at capture time when
|
|
131
|
+
* `autoLinkSimilar` is true (default). `via` is left empty in 0.1.0;
|
|
132
|
+
* derive it from a follow-up Cypher walk if you need the full path.
|
|
133
|
+
*/
|
|
134
|
+
recallRelated(memoryId: string, options?: RecallRelatedOptions): Promise<RelatedMemoryResult[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Score candidate memories against a query.
|
|
137
|
+
*
|
|
138
|
+
* Two execution modes:
|
|
139
|
+
* - **Model mode**: if an AutoML model named
|
|
140
|
+
* `openclaw_memory_relevance[_<workspace>]` exists, the candidates'
|
|
141
|
+
* feature vectors are passed through `model.predict()`.
|
|
142
|
+
* - **Heuristic mode** (default fallback): `relevance = 0.6 * cosine +
|
|
143
|
+
* 0.25 * exp(-age_days/14) + 0.15 * importance`.
|
|
144
|
+
*
|
|
145
|
+
* Train the model with `trainRelevanceModel(feedback)` to switch to model
|
|
146
|
+
* mode automatically on the next call.
|
|
147
|
+
*
|
|
148
|
+
* @param query - The user query / agent prompt to score relevance against.
|
|
149
|
+
* @param candidates - Memories to score (typically the top-K of a recall).
|
|
150
|
+
* @returns Candidates with a `relevance` score in [0, 1], not re-sorted.
|
|
151
|
+
*/
|
|
152
|
+
predictRelevance(query: string, candidates: MemoryEntry[]): Promise<RelevanceScoredMemory[]>;
|
|
153
|
+
/**
|
|
154
|
+
* Train (or retrain) the AutoML model used by `predictRelevance`.
|
|
155
|
+
*
|
|
156
|
+
* @param feedback - Array of `{ memoryId, queryText, score }` samples.
|
|
157
|
+
* Requires at least {@link MIN_TRAINING_SAMPLES} samples;
|
|
158
|
+
* throws otherwise.
|
|
159
|
+
* @returns The id of the trained model.
|
|
160
|
+
*/
|
|
161
|
+
trainRelevanceModel(feedback: RelevanceFeedback[]): Promise<{
|
|
162
|
+
modelId: string;
|
|
163
|
+
modelName: string;
|
|
164
|
+
}>;
|
|
165
|
+
}
|
|
166
|
+
declare const memoryPlugin: {
|
|
167
|
+
id: string;
|
|
168
|
+
name: string;
|
|
169
|
+
description: string;
|
|
170
|
+
kind: "memory";
|
|
171
|
+
configSchema: {
|
|
172
|
+
parse(value: unknown): import("./config.js").MemoryConfig;
|
|
173
|
+
uiHints: {
|
|
174
|
+
"embedding.apiKey": {
|
|
175
|
+
label: string;
|
|
176
|
+
sensitive: boolean;
|
|
177
|
+
placeholder: string;
|
|
178
|
+
help: string;
|
|
179
|
+
};
|
|
180
|
+
"embedding.model": {
|
|
181
|
+
label: string;
|
|
182
|
+
placeholder: string;
|
|
183
|
+
help: string;
|
|
184
|
+
};
|
|
185
|
+
"synapcores.host": {
|
|
186
|
+
label: string;
|
|
187
|
+
placeholder: string;
|
|
188
|
+
help: string;
|
|
189
|
+
};
|
|
190
|
+
"synapcores.port": {
|
|
191
|
+
label: string;
|
|
192
|
+
placeholder: string;
|
|
193
|
+
help: string;
|
|
194
|
+
};
|
|
195
|
+
"synapcores.apiKey": {
|
|
196
|
+
label: string;
|
|
197
|
+
sensitive: boolean;
|
|
198
|
+
placeholder: string;
|
|
199
|
+
help: string;
|
|
200
|
+
};
|
|
201
|
+
"synapcores.useHttps": {
|
|
202
|
+
label: string;
|
|
203
|
+
advanced: boolean;
|
|
204
|
+
help: string;
|
|
205
|
+
};
|
|
206
|
+
collection: {
|
|
207
|
+
label: string;
|
|
208
|
+
placeholder: string;
|
|
209
|
+
advanced: boolean;
|
|
210
|
+
help: string;
|
|
211
|
+
};
|
|
212
|
+
graph: {
|
|
213
|
+
label: string;
|
|
214
|
+
placeholder: string;
|
|
215
|
+
advanced: boolean;
|
|
216
|
+
help: string;
|
|
217
|
+
};
|
|
218
|
+
autoCapture: {
|
|
219
|
+
label: string;
|
|
220
|
+
help: string;
|
|
221
|
+
};
|
|
222
|
+
autoRecall: {
|
|
223
|
+
label: string;
|
|
224
|
+
help: string;
|
|
225
|
+
};
|
|
226
|
+
autoLinkSimilar: {
|
|
227
|
+
label: string;
|
|
228
|
+
advanced: boolean;
|
|
229
|
+
help: string;
|
|
230
|
+
};
|
|
231
|
+
workspace: {
|
|
232
|
+
label: string;
|
|
233
|
+
advanced: boolean;
|
|
234
|
+
help: string;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
register(api: OpenClawPluginApi): void;
|
|
239
|
+
};
|
|
240
|
+
export default memoryPlugin;
|
|
241
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAO7D,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,aAAa,CAAC;AAMrB,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;I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