@totalreclaw/core 2.6.0 → 2.7.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 +82 -0
- package/nodejs/totalreclaw_core.d.ts +82 -3
- package/nodejs/totalreclaw_core.js +246 -4
- package/nodejs/totalreclaw_core_bg.wasm +0 -0
- package/nodejs/totalreclaw_core_bg.wasm.d.ts +80 -72
- package/package.json +2 -2
- package/web/totalreclaw_core.d.ts +162 -75
- package/web/totalreclaw_core.js +238 -4
- package/web/totalreclaw_core_bg.wasm +0 -0
- package/web/totalreclaw_core_bg.wasm.d.ts +80 -72
- package/nodejs/README.md +0 -40
- package/web/README.md +0 -40
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# @totalreclaw/core
|
|
2
|
+
|
|
3
|
+
The shared TotalReclaw core library, compiled from Rust to WebAssembly. It holds the encryption, blind indexing, reranking, key and wallet derivation, and on-chain encoding code that every TotalReclaw client uses, so the OpenClaw plugin, the MCP server, the NanoClaw skill and the Python client all produce byte-identical results.
|
|
4
|
+
|
|
5
|
+
The same crate also ships as [`totalreclaw-core`](https://crates.io/crates/totalreclaw-core) on crates.io (Rust) and [`totalreclaw-core`](https://pypi.org/project/totalreclaw-core/) on PyPI (Python bindings).
|
|
6
|
+
|
|
7
|
+
## Should you install this?
|
|
8
|
+
|
|
9
|
+
Probably not directly. If you want encrypted memory for an AI agent, install the integration for your agent instead. Each one pulls in `@totalreclaw/core` for you:
|
|
10
|
+
|
|
11
|
+
| Agent | Package | Guide |
|
|
12
|
+
|-------|---------|-------|
|
|
13
|
+
| OpenClaw | [`@totalreclaw/totalreclaw`](https://www.npmjs.com/package/@totalreclaw/totalreclaw) | [OpenClaw setup](https://github.com/graphprotocol/totalreclaw/blob/main/docs/guides/openclaw-setup.md) |
|
|
14
|
+
| Claude Code, Claude Desktop, Cursor, other MCP hosts | [`@totalreclaw/mcp-server`](https://www.npmjs.com/package/@totalreclaw/mcp-server) | [Claude Code setup](https://github.com/graphprotocol/totalreclaw/blob/main/docs/guides/claude-code-setup.md) |
|
|
15
|
+
| Hermes | [`totalreclaw`](https://pypi.org/project/totalreclaw/) on PyPI | [Hermes setup](https://github.com/graphprotocol/totalreclaw/blob/main/docs/guides/hermes-setup.md) |
|
|
16
|
+
| NanoClaw | [`@totalreclaw/skill-nanoclaw`](https://www.npmjs.com/package/@totalreclaw/skill-nanoclaw) | [NanoClaw guide](https://github.com/graphprotocol/totalreclaw/blob/main/docs/guides/nanoclaw-getting-started.md) |
|
|
17
|
+
|
|
18
|
+
Install `@totalreclaw/core` yourself only if you are building a TotalReclaw client or tool and need the same primitives.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @totalreclaw/core
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Entry points
|
|
27
|
+
|
|
28
|
+
| Import | Build | Use it from |
|
|
29
|
+
|--------|-------|-------------|
|
|
30
|
+
| `@totalreclaw/core` | wasm-bindgen `nodejs` target (CommonJS; loads the `.wasm` file synchronously) | Node.js |
|
|
31
|
+
| `@totalreclaw/core/web` | wasm-bindgen `web` target (ES module; call the default `init()` export once before anything else) | Browsers and bundlers |
|
|
32
|
+
|
|
33
|
+
Both builds come from the same crate and version and expose the same functions. TypeScript declarations ship with each build.
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
Node.js:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const { randomBytes } = require('node:crypto');
|
|
41
|
+
const core = require('@totalreclaw/core');
|
|
42
|
+
|
|
43
|
+
// XChaCha20-Poly1305. Keys are 32 bytes, passed as 64 hex characters.
|
|
44
|
+
const key = randomBytes(32).toString('hex');
|
|
45
|
+
const blob = core.encrypt('prefers dark mode', key); // base64: nonce || tag || ciphertext
|
|
46
|
+
console.log(core.decrypt(blob, key)); // 'prefers dark mode'
|
|
47
|
+
|
|
48
|
+
// Blind indices: hex SHA-256 hashes of the normalized tokens and their stems.
|
|
49
|
+
// The server matches on these and never sees the words.
|
|
50
|
+
console.log(core.generateBlindIndices('prefers dark mode'));
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Browser:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import init, { encrypt, decrypt } from '@totalreclaw/core/web';
|
|
57
|
+
|
|
58
|
+
await init(); // fetches totalreclaw_core_bg.wasm from next to the module
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## What's included
|
|
62
|
+
|
|
63
|
+
Function names below are the JavaScript exports. Most functions take and return plain strings (hex keys, base64 blobs, JSON); see `totalreclaw_core.d.ts` for exact signatures.
|
|
64
|
+
|
|
65
|
+
- **Encryption and indexing**: `encrypt`, `decrypt`, `generateBlindIndices`, `generateContentFingerprint`, `normalizeText`, `computeAuthKeyHash`.
|
|
66
|
+
- **Key derivation**: `deriveKeysFromMnemonic`, `deriveLshSeed`, `deriveBundleFromMnemonic`, plus `parseBundleV1` / `validateBundleV1` for credential bundles.
|
|
67
|
+
- **Store and search**: `prepareFact`, `prepareTombstone`, `encodeFactProtobuf`, `canonicalizeClaim`, `generateSearchTrapdoors`, `parseSearchResponse`, `rerank`, `rerankWithConfig`, `decryptAndRerank`, `cosineSimilarity`.
|
|
68
|
+
- **Wallet and ERC-4337**: `deriveEoa`, `deriveEoaAddress`, `encodeSingleCall`, `encodeBatchCall`, `hashUserOp`, `signUserOp`.
|
|
69
|
+
- **Dedup, contradictions and pins**: `detectContradictions`, `resolvePair`, `resolveWithCandidates`, `classifyPinIntent`, `isPinnedClaim`, decision-log helpers.
|
|
70
|
+
- **Extraction prompts**: `getExtractionSystemPrompt`, `getCompactionSystemPrompt`, `getDebriefSystemPrompt`.
|
|
71
|
+
|
|
72
|
+
Apart from the web build's `init()` loading the `.wasm` file, the library does no network I/O. All key material stays in your process. Functions that take a recovery phrase exist for client implementations that already hold the user's phrase; never log a phrase, put it in a prompt, or send it to an LLM.
|
|
73
|
+
|
|
74
|
+
## Links
|
|
75
|
+
|
|
76
|
+
- Repository: <https://github.com/graphprotocol/totalreclaw> (source in `rust/totalreclaw-core`)
|
|
77
|
+
- Website: <https://totalreclaw.xyz>
|
|
78
|
+
- Issues: <https://github.com/graphprotocol/totalreclaw/issues>
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT
|
|
@@ -104,6 +104,22 @@ export function buildDebriefPrompt(stored_facts_json: string): string;
|
|
|
104
104
|
*/
|
|
105
105
|
export function buildDecisionLogEntries(actions_json: string, new_claim_json: string, existing_claims_json: string, mode: string, now_unix: bigint): string;
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Render the "Existing memories" block appended to the extraction user
|
|
109
|
+
* prompt (PRD-04 DEP-3).
|
|
110
|
+
*
|
|
111
|
+
* Each argument is a JSON array of `{ id: string, text: string }` objects
|
|
112
|
+
* (`"null"` = empty section; extra fields such as `embedding` are ignored).
|
|
113
|
+
* Pinned first, then topical, then recent; dedupe by fact id; at most `cap`
|
|
114
|
+
* lines; returns `""` when no line survives. Malformed JSON → `JsError`.
|
|
115
|
+
*
|
|
116
|
+
* `cap` defaults to 30 when omitted (`undefined` / `null`). It must be a
|
|
117
|
+
* non-negative integer: a negative, fractional, `NaN` or infinite value
|
|
118
|
+
* throws instead of being coerced (a plain `usize` parameter would turn `-1`
|
|
119
|
+
* into "no cap" and `NaN` into an empty block).
|
|
120
|
+
*/
|
|
121
|
+
export function buildDedupContext(topical_json: string, pinned_json: string, recent_json: string, cap?: number | null): string;
|
|
122
|
+
|
|
107
123
|
/**
|
|
108
124
|
* Build the LLM prompt for digest compilation.
|
|
109
125
|
* `claims_json`: JSON array of Claim (must be non-empty).
|
|
@@ -214,6 +230,18 @@ export function computeScoreComponents(claim_json: string, now_unix_seconds: big
|
|
|
214
230
|
*/
|
|
215
231
|
export function cosineSimilarity(a: Float32Array, b: Float32Array): number;
|
|
216
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Decide whether a new fact should be written (store-time write gate).
|
|
235
|
+
*
|
|
236
|
+
* `embeddingJson`: JSON number array, or `"null"` / `"[]"`.
|
|
237
|
+
* `candidatesJson`: JSON array of `{id, text, embedding?, pinned?}`.
|
|
238
|
+
* `mode`: `"auto"` | `"explicit"` | `"exact_only"`.
|
|
239
|
+
* `threshold`: cosine threshold in (0, 1]; omitted means 0.85.
|
|
240
|
+
*
|
|
241
|
+
* Returns JSON `{action: "store"|"skip"|"confirm", match: null | {...}}`.
|
|
242
|
+
*/
|
|
243
|
+
export function decideWrite(text: string, embedding_json: string, candidates_json: string, mode: string, threshold?: number | null): string;
|
|
244
|
+
|
|
217
245
|
/**
|
|
218
246
|
* Decode any embedding payload into a Float32Array (the forever-reader).
|
|
219
247
|
*
|
|
@@ -248,6 +276,12 @@ export function decrypt(encrypted_base64: string, encryption_key_hex: string): s
|
|
|
248
276
|
*/
|
|
249
277
|
export function decryptAndRerank(facts_json: string, query: string, query_embedding: Float32Array, encryption_key_hex: string, top_k: number): any;
|
|
250
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Default recall boost for pinned candidates (PRD-04 F1 / DEP-5) — 1.5.
|
|
281
|
+
* Pass it as `pin_boost` to `rerankWithConfig` to enable the boost.
|
|
282
|
+
*/
|
|
283
|
+
export function defaultPinBoost(): number;
|
|
284
|
+
|
|
251
285
|
/**
|
|
252
286
|
* Return the locked-default [`PinConfig`] as JSON. Clients that don't want
|
|
253
287
|
* to retune can pass this verbatim to [`wasm_pin_boost`].
|
|
@@ -463,6 +497,14 @@ export function findLoserClaimInDecisionLog(fact_id: string, log_content: string
|
|
|
463
497
|
*/
|
|
464
498
|
export function findNearDuplicate(new_embedding: Float32Array, existing_json: string, threshold: number): any;
|
|
465
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Ids of the forgotten entries an explicit remember of `text` releases.
|
|
502
|
+
*
|
|
503
|
+
* Same JSON inputs as `matchForgotten`. Returns a JSON array of entry ids.
|
|
504
|
+
* Malformed JSON → `JsError`.
|
|
505
|
+
*/
|
|
506
|
+
export function forgetReleaseIds(text: string, embedding_json: string, entries_json: string): string;
|
|
507
|
+
|
|
466
508
|
/**
|
|
467
509
|
* Unix seconds → `"YYYY-MM-DD"` (UTC). Returns `""` for `0` or negative.
|
|
468
510
|
*
|
|
@@ -667,6 +709,12 @@ export function hashUserOp(userop_json: string, entrypoint: string, chain_id: bi
|
|
|
667
709
|
*/
|
|
668
710
|
export function hexBlobToBase64(hex_blob: string): string | undefined;
|
|
669
711
|
|
|
712
|
+
/**
|
|
713
|
+
* True when `text` is a note about deleting a memory ("User asked to forget
|
|
714
|
+
* X") rather than a fact about the user.
|
|
715
|
+
*/
|
|
716
|
+
export function isForgetRequest(text: string): boolean;
|
|
717
|
+
|
|
670
718
|
/**
|
|
671
719
|
* Check whether a JSON-serialized claim has pinned status.
|
|
672
720
|
*/
|
|
@@ -699,6 +747,17 @@ export function legacyClaimFallbackWeight(): number;
|
|
|
699
747
|
*/
|
|
700
748
|
export function mapTypeToCategory(value: string): any;
|
|
701
749
|
|
|
750
|
+
/**
|
|
751
|
+
* Does an extracted candidate restate a fact the user explicitly forgot?
|
|
752
|
+
*
|
|
753
|
+
* `embeddingJson` is a JSON array of numbers or `"null"`. `entriesJson` is a
|
|
754
|
+
* JSON array of `{ id, text, embedding? }` (the client's forgotten-facts
|
|
755
|
+
* ledger, decrypted in memory). Returns `"null"` or
|
|
756
|
+
* `{ id, reason, cosine }` as JSON, where reason is `exact` / `subset` /
|
|
757
|
+
* `superset` / `anchor` / `clause`. Malformed JSON → `JsError`.
|
|
758
|
+
*/
|
|
759
|
+
export function matchForgotten(text: string, embedding_json: string, entries_json: string): string;
|
|
760
|
+
|
|
702
761
|
/**
|
|
703
762
|
* Merge multiple SubgraphFact sets from parallel query reformulations via RRF.
|
|
704
763
|
*
|
|
@@ -714,6 +773,11 @@ export function mergeExpansionResults(fact_sets_json: string, rrf_k: number): an
|
|
|
714
773
|
*/
|
|
715
774
|
export function normalizeEntityName(name: string): string;
|
|
716
775
|
|
|
776
|
+
/**
|
|
777
|
+
* Normalize a fact for the write gate's exact-duplicate check.
|
|
778
|
+
*/
|
|
779
|
+
export function normalizeFactText(text: string): string;
|
|
780
|
+
|
|
717
781
|
/**
|
|
718
782
|
* Normalize text (NFC, lowercase, collapse whitespace, trim).
|
|
719
783
|
*/
|
|
@@ -816,6 +880,15 @@ export function parseTriageResponse(llm_output: string): any;
|
|
|
816
880
|
*/
|
|
817
881
|
export function parseWeightsFile(content: string): string;
|
|
818
882
|
|
|
883
|
+
/**
|
|
884
|
+
* Classify a candidate memory text before it is stored.
|
|
885
|
+
*
|
|
886
|
+
* Returns the canonical decision JSON (identical bytes to the PyO3
|
|
887
|
+
* `pii_filter`): `{"decision":"allow"}` or
|
|
888
|
+
* `{"decision":"block"|"flag","category":"<tag>","message":"<user-facing text>"}`.
|
|
889
|
+
*/
|
|
890
|
+
export function piiFilter(text: string): string;
|
|
891
|
+
|
|
819
892
|
/**
|
|
820
893
|
* Compute the [`PinTier`]'s multiplicative boost at a given timestamp.
|
|
821
894
|
*
|
|
@@ -881,16 +954,22 @@ export function recallContextHeader(now_unix: bigint): string;
|
|
|
881
954
|
export function rerank(query: string, query_embedding: Float32Array, candidates_json: string, top_k: number): any;
|
|
882
955
|
|
|
883
956
|
/**
|
|
884
|
-
* Rerank candidates with a config flag (Retrieval v2 Tier 1)
|
|
957
|
+
* Rerank candidates with a config flag (Retrieval v2 Tier 1) and an optional
|
|
958
|
+
* pin boost (PRD-04 F1 / DEP-5).
|
|
885
959
|
*
|
|
886
960
|
* When `apply_source_weights` is `true`, each candidate's final score is
|
|
887
961
|
* multiplied by the provenance weight from its `source` field (legacy
|
|
888
962
|
* candidates without `source` use the v0 fallback weight).
|
|
889
963
|
*
|
|
890
|
-
* `
|
|
964
|
+
* When `pin_boost` is a number > 1.0, candidates carrying `"pinned": true`
|
|
965
|
+
* rank as if their BM25 and cosine scores were multiplied by it (ignored when
|
|
966
|
+
* `query_embedding` is empty). Omitted,
|
|
967
|
+
* `undefined` or `null` keeps the pre-DEP-5 ranking bit-for-bit.
|
|
968
|
+
*
|
|
969
|
+
* `candidates_json`: JSON array of `{ id, text, embedding, timestamp, source?, pinned? }` objects.
|
|
891
970
|
* Returns a JsValue (array of `RankedResult` objects including `source_weight`).
|
|
892
971
|
*/
|
|
893
|
-
export function rerankWithConfig(query: string, query_embedding: Float32Array, candidates_json: string, top_k: number, apply_source_weights: boolean): any;
|
|
972
|
+
export function rerankWithConfig(query: string, query_embedding: Float32Array, candidates_json: string, top_k: number, apply_source_weights: boolean, pin_boost?: number | null): any;
|
|
894
973
|
|
|
895
974
|
/**
|
|
896
975
|
* Run the resolution formula on two contradicting claims; returns ResolutionOutcome JSON.
|
|
@@ -344,6 +344,51 @@ function buildDecisionLogEntries(actions_json, new_claim_json, existing_claims_j
|
|
|
344
344
|
}
|
|
345
345
|
exports.buildDecisionLogEntries = buildDecisionLogEntries;
|
|
346
346
|
|
|
347
|
+
/**
|
|
348
|
+
* Render the "Existing memories" block appended to the extraction user
|
|
349
|
+
* prompt (PRD-04 DEP-3).
|
|
350
|
+
*
|
|
351
|
+
* Each argument is a JSON array of `{ id: string, text: string }` objects
|
|
352
|
+
* (`"null"` = empty section; extra fields such as `embedding` are ignored).
|
|
353
|
+
* Pinned first, then topical, then recent; dedupe by fact id; at most `cap`
|
|
354
|
+
* lines; returns `""` when no line survives. Malformed JSON → `JsError`.
|
|
355
|
+
*
|
|
356
|
+
* `cap` defaults to 30 when omitted (`undefined` / `null`). It must be a
|
|
357
|
+
* non-negative integer: a negative, fractional, `NaN` or infinite value
|
|
358
|
+
* throws instead of being coerced (a plain `usize` parameter would turn `-1`
|
|
359
|
+
* into "no cap" and `NaN` into an empty block).
|
|
360
|
+
* @param {string} topical_json
|
|
361
|
+
* @param {string} pinned_json
|
|
362
|
+
* @param {string} recent_json
|
|
363
|
+
* @param {number | null} [cap]
|
|
364
|
+
* @returns {string}
|
|
365
|
+
*/
|
|
366
|
+
function buildDedupContext(topical_json, pinned_json, recent_json, cap) {
|
|
367
|
+
let deferred5_0;
|
|
368
|
+
let deferred5_1;
|
|
369
|
+
try {
|
|
370
|
+
const ptr0 = passStringToWasm0(topical_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
371
|
+
const len0 = WASM_VECTOR_LEN;
|
|
372
|
+
const ptr1 = passStringToWasm0(pinned_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
373
|
+
const len1 = WASM_VECTOR_LEN;
|
|
374
|
+
const ptr2 = passStringToWasm0(recent_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
375
|
+
const len2 = WASM_VECTOR_LEN;
|
|
376
|
+
const ret = wasm.buildDedupContext(ptr0, len0, ptr1, len1, ptr2, len2, !isLikeNone(cap), isLikeNone(cap) ? 0 : cap);
|
|
377
|
+
var ptr4 = ret[0];
|
|
378
|
+
var len4 = ret[1];
|
|
379
|
+
if (ret[3]) {
|
|
380
|
+
ptr4 = 0; len4 = 0;
|
|
381
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
382
|
+
}
|
|
383
|
+
deferred5_0 = ptr4;
|
|
384
|
+
deferred5_1 = len4;
|
|
385
|
+
return getStringFromWasm0(ptr4, len4);
|
|
386
|
+
} finally {
|
|
387
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
exports.buildDedupContext = buildDedupContext;
|
|
391
|
+
|
|
347
392
|
/**
|
|
348
393
|
* Build the LLM prompt for digest compilation.
|
|
349
394
|
* `claims_json`: JSON array of Claim (must be non-empty).
|
|
@@ -752,6 +797,50 @@ function cosineSimilarity(a, b) {
|
|
|
752
797
|
}
|
|
753
798
|
exports.cosineSimilarity = cosineSimilarity;
|
|
754
799
|
|
|
800
|
+
/**
|
|
801
|
+
* Decide whether a new fact should be written (store-time write gate).
|
|
802
|
+
*
|
|
803
|
+
* `embeddingJson`: JSON number array, or `"null"` / `"[]"`.
|
|
804
|
+
* `candidatesJson`: JSON array of `{id, text, embedding?, pinned?}`.
|
|
805
|
+
* `mode`: `"auto"` | `"explicit"` | `"exact_only"`.
|
|
806
|
+
* `threshold`: cosine threshold in (0, 1]; omitted means 0.85.
|
|
807
|
+
*
|
|
808
|
+
* Returns JSON `{action: "store"|"skip"|"confirm", match: null | {...}}`.
|
|
809
|
+
* @param {string} text
|
|
810
|
+
* @param {string} embedding_json
|
|
811
|
+
* @param {string} candidates_json
|
|
812
|
+
* @param {string} mode
|
|
813
|
+
* @param {number | null} [threshold]
|
|
814
|
+
* @returns {string}
|
|
815
|
+
*/
|
|
816
|
+
function decideWrite(text, embedding_json, candidates_json, mode, threshold) {
|
|
817
|
+
let deferred6_0;
|
|
818
|
+
let deferred6_1;
|
|
819
|
+
try {
|
|
820
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
821
|
+
const len0 = WASM_VECTOR_LEN;
|
|
822
|
+
const ptr1 = passStringToWasm0(embedding_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
823
|
+
const len1 = WASM_VECTOR_LEN;
|
|
824
|
+
const ptr2 = passStringToWasm0(candidates_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
825
|
+
const len2 = WASM_VECTOR_LEN;
|
|
826
|
+
const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
827
|
+
const len3 = WASM_VECTOR_LEN;
|
|
828
|
+
const ret = wasm.decideWrite(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, !isLikeNone(threshold), isLikeNone(threshold) ? 0 : threshold);
|
|
829
|
+
var ptr5 = ret[0];
|
|
830
|
+
var len5 = ret[1];
|
|
831
|
+
if (ret[3]) {
|
|
832
|
+
ptr5 = 0; len5 = 0;
|
|
833
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
834
|
+
}
|
|
835
|
+
deferred6_0 = ptr5;
|
|
836
|
+
deferred6_1 = len5;
|
|
837
|
+
return getStringFromWasm0(ptr5, len5);
|
|
838
|
+
} finally {
|
|
839
|
+
wasm.__wbindgen_free(deferred6_0, deferred6_1, 1);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
exports.decideWrite = decideWrite;
|
|
843
|
+
|
|
755
844
|
/**
|
|
756
845
|
* Decode any embedding payload into a Float32Array (the forever-reader).
|
|
757
846
|
*
|
|
@@ -845,6 +934,17 @@ function decryptAndRerank(facts_json, query, query_embedding, encryption_key_hex
|
|
|
845
934
|
}
|
|
846
935
|
exports.decryptAndRerank = decryptAndRerank;
|
|
847
936
|
|
|
937
|
+
/**
|
|
938
|
+
* Default recall boost for pinned candidates (PRD-04 F1 / DEP-5) — 1.5.
|
|
939
|
+
* Pass it as `pin_boost` to `rerankWithConfig` to enable the boost.
|
|
940
|
+
* @returns {number}
|
|
941
|
+
*/
|
|
942
|
+
function defaultPinBoost() {
|
|
943
|
+
const ret = wasm.defaultPinBoost();
|
|
944
|
+
return ret;
|
|
945
|
+
}
|
|
946
|
+
exports.defaultPinBoost = defaultPinBoost;
|
|
947
|
+
|
|
848
948
|
/**
|
|
849
949
|
* Return the locked-default [`PinConfig`] as JSON. Clients that don't want
|
|
850
950
|
* to retune can pass this verbatim to [`wasm_pin_boost`].
|
|
@@ -1548,6 +1648,42 @@ function findNearDuplicate(new_embedding, existing_json, threshold) {
|
|
|
1548
1648
|
}
|
|
1549
1649
|
exports.findNearDuplicate = findNearDuplicate;
|
|
1550
1650
|
|
|
1651
|
+
/**
|
|
1652
|
+
* Ids of the forgotten entries an explicit remember of `text` releases.
|
|
1653
|
+
*
|
|
1654
|
+
* Same JSON inputs as `matchForgotten`. Returns a JSON array of entry ids.
|
|
1655
|
+
* Malformed JSON → `JsError`.
|
|
1656
|
+
* @param {string} text
|
|
1657
|
+
* @param {string} embedding_json
|
|
1658
|
+
* @param {string} entries_json
|
|
1659
|
+
* @returns {string}
|
|
1660
|
+
*/
|
|
1661
|
+
function forgetReleaseIds(text, embedding_json, entries_json) {
|
|
1662
|
+
let deferred5_0;
|
|
1663
|
+
let deferred5_1;
|
|
1664
|
+
try {
|
|
1665
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1666
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1667
|
+
const ptr1 = passStringToWasm0(embedding_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1668
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1669
|
+
const ptr2 = passStringToWasm0(entries_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1670
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1671
|
+
const ret = wasm.forgetReleaseIds(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1672
|
+
var ptr4 = ret[0];
|
|
1673
|
+
var len4 = ret[1];
|
|
1674
|
+
if (ret[3]) {
|
|
1675
|
+
ptr4 = 0; len4 = 0;
|
|
1676
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1677
|
+
}
|
|
1678
|
+
deferred5_0 = ptr4;
|
|
1679
|
+
deferred5_1 = len4;
|
|
1680
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1681
|
+
} finally {
|
|
1682
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
exports.forgetReleaseIds = forgetReleaseIds;
|
|
1686
|
+
|
|
1551
1687
|
/**
|
|
1552
1688
|
* Unix seconds → `"YYYY-MM-DD"` (UTC). Returns `""` for `0` or negative.
|
|
1553
1689
|
*
|
|
@@ -2089,6 +2225,20 @@ function hexBlobToBase64(hex_blob) {
|
|
|
2089
2225
|
}
|
|
2090
2226
|
exports.hexBlobToBase64 = hexBlobToBase64;
|
|
2091
2227
|
|
|
2228
|
+
/**
|
|
2229
|
+
* True when `text` is a note about deleting a memory ("User asked to forget
|
|
2230
|
+
* X") rather than a fact about the user.
|
|
2231
|
+
* @param {string} text
|
|
2232
|
+
* @returns {boolean}
|
|
2233
|
+
*/
|
|
2234
|
+
function isForgetRequest(text) {
|
|
2235
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2236
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2237
|
+
const ret = wasm.isForgetRequest(ptr0, len0);
|
|
2238
|
+
return ret !== 0;
|
|
2239
|
+
}
|
|
2240
|
+
exports.isForgetRequest = isForgetRequest;
|
|
2241
|
+
|
|
2092
2242
|
/**
|
|
2093
2243
|
* Check whether a JSON-serialized claim has pinned status.
|
|
2094
2244
|
* @param {string} claim_json
|
|
@@ -2158,6 +2308,45 @@ function mapTypeToCategory(value) {
|
|
|
2158
2308
|
}
|
|
2159
2309
|
exports.mapTypeToCategory = mapTypeToCategory;
|
|
2160
2310
|
|
|
2311
|
+
/**
|
|
2312
|
+
* Does an extracted candidate restate a fact the user explicitly forgot?
|
|
2313
|
+
*
|
|
2314
|
+
* `embeddingJson` is a JSON array of numbers or `"null"`. `entriesJson` is a
|
|
2315
|
+
* JSON array of `{ id, text, embedding? }` (the client's forgotten-facts
|
|
2316
|
+
* ledger, decrypted in memory). Returns `"null"` or
|
|
2317
|
+
* `{ id, reason, cosine }` as JSON, where reason is `exact` / `subset` /
|
|
2318
|
+
* `superset` / `anchor` / `clause`. Malformed JSON → `JsError`.
|
|
2319
|
+
* @param {string} text
|
|
2320
|
+
* @param {string} embedding_json
|
|
2321
|
+
* @param {string} entries_json
|
|
2322
|
+
* @returns {string}
|
|
2323
|
+
*/
|
|
2324
|
+
function matchForgotten(text, embedding_json, entries_json) {
|
|
2325
|
+
let deferred5_0;
|
|
2326
|
+
let deferred5_1;
|
|
2327
|
+
try {
|
|
2328
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2329
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2330
|
+
const ptr1 = passStringToWasm0(embedding_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2331
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2332
|
+
const ptr2 = passStringToWasm0(entries_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2333
|
+
const len2 = WASM_VECTOR_LEN;
|
|
2334
|
+
const ret = wasm.matchForgotten(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
2335
|
+
var ptr4 = ret[0];
|
|
2336
|
+
var len4 = ret[1];
|
|
2337
|
+
if (ret[3]) {
|
|
2338
|
+
ptr4 = 0; len4 = 0;
|
|
2339
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
2340
|
+
}
|
|
2341
|
+
deferred5_0 = ptr4;
|
|
2342
|
+
deferred5_1 = len4;
|
|
2343
|
+
return getStringFromWasm0(ptr4, len4);
|
|
2344
|
+
} finally {
|
|
2345
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
exports.matchForgotten = matchForgotten;
|
|
2349
|
+
|
|
2161
2350
|
/**
|
|
2162
2351
|
* Merge multiple SubgraphFact sets from parallel query reformulations via RRF.
|
|
2163
2352
|
*
|
|
@@ -2201,6 +2390,27 @@ function normalizeEntityName(name) {
|
|
|
2201
2390
|
}
|
|
2202
2391
|
exports.normalizeEntityName = normalizeEntityName;
|
|
2203
2392
|
|
|
2393
|
+
/**
|
|
2394
|
+
* Normalize a fact for the write gate's exact-duplicate check.
|
|
2395
|
+
* @param {string} text
|
|
2396
|
+
* @returns {string}
|
|
2397
|
+
*/
|
|
2398
|
+
function normalizeFactText(text) {
|
|
2399
|
+
let deferred2_0;
|
|
2400
|
+
let deferred2_1;
|
|
2401
|
+
try {
|
|
2402
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2403
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2404
|
+
const ret = wasm.normalizeFactText(ptr0, len0);
|
|
2405
|
+
deferred2_0 = ret[0];
|
|
2406
|
+
deferred2_1 = ret[1];
|
|
2407
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2408
|
+
} finally {
|
|
2409
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
exports.normalizeFactText = normalizeFactText;
|
|
2413
|
+
|
|
2204
2414
|
/**
|
|
2205
2415
|
* Normalize text (NFC, lowercase, collapse whitespace, trim).
|
|
2206
2416
|
* @param {string} text
|
|
@@ -2521,6 +2731,31 @@ function parseWeightsFile(content) {
|
|
|
2521
2731
|
}
|
|
2522
2732
|
exports.parseWeightsFile = parseWeightsFile;
|
|
2523
2733
|
|
|
2734
|
+
/**
|
|
2735
|
+
* Classify a candidate memory text before it is stored.
|
|
2736
|
+
*
|
|
2737
|
+
* Returns the canonical decision JSON (identical bytes to the PyO3
|
|
2738
|
+
* `pii_filter`): `{"decision":"allow"}` or
|
|
2739
|
+
* `{"decision":"block"|"flag","category":"<tag>","message":"<user-facing text>"}`.
|
|
2740
|
+
* @param {string} text
|
|
2741
|
+
* @returns {string}
|
|
2742
|
+
*/
|
|
2743
|
+
function piiFilter(text) {
|
|
2744
|
+
let deferred2_0;
|
|
2745
|
+
let deferred2_1;
|
|
2746
|
+
try {
|
|
2747
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2748
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2749
|
+
const ret = wasm.piiFilter(ptr0, len0);
|
|
2750
|
+
deferred2_0 = ret[0];
|
|
2751
|
+
deferred2_1 = ret[1];
|
|
2752
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2753
|
+
} finally {
|
|
2754
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
exports.piiFilter = piiFilter;
|
|
2758
|
+
|
|
2524
2759
|
/**
|
|
2525
2760
|
* Compute the [`PinTier`]'s multiplicative boost at a given timestamp.
|
|
2526
2761
|
*
|
|
@@ -2732,29 +2967,36 @@ function rerank(query, query_embedding, candidates_json, top_k) {
|
|
|
2732
2967
|
exports.rerank = rerank;
|
|
2733
2968
|
|
|
2734
2969
|
/**
|
|
2735
|
-
* Rerank candidates with a config flag (Retrieval v2 Tier 1)
|
|
2970
|
+
* Rerank candidates with a config flag (Retrieval v2 Tier 1) and an optional
|
|
2971
|
+
* pin boost (PRD-04 F1 / DEP-5).
|
|
2736
2972
|
*
|
|
2737
2973
|
* When `apply_source_weights` is `true`, each candidate's final score is
|
|
2738
2974
|
* multiplied by the provenance weight from its `source` field (legacy
|
|
2739
2975
|
* candidates without `source` use the v0 fallback weight).
|
|
2740
2976
|
*
|
|
2741
|
-
* `
|
|
2977
|
+
* When `pin_boost` is a number > 1.0, candidates carrying `"pinned": true`
|
|
2978
|
+
* rank as if their BM25 and cosine scores were multiplied by it (ignored when
|
|
2979
|
+
* `query_embedding` is empty). Omitted,
|
|
2980
|
+
* `undefined` or `null` keeps the pre-DEP-5 ranking bit-for-bit.
|
|
2981
|
+
*
|
|
2982
|
+
* `candidates_json`: JSON array of `{ id, text, embedding, timestamp, source?, pinned? }` objects.
|
|
2742
2983
|
* Returns a JsValue (array of `RankedResult` objects including `source_weight`).
|
|
2743
2984
|
* @param {string} query
|
|
2744
2985
|
* @param {Float32Array} query_embedding
|
|
2745
2986
|
* @param {string} candidates_json
|
|
2746
2987
|
* @param {number} top_k
|
|
2747
2988
|
* @param {boolean} apply_source_weights
|
|
2989
|
+
* @param {number | null} [pin_boost]
|
|
2748
2990
|
* @returns {any}
|
|
2749
2991
|
*/
|
|
2750
|
-
function rerankWithConfig(query, query_embedding, candidates_json, top_k, apply_source_weights) {
|
|
2992
|
+
function rerankWithConfig(query, query_embedding, candidates_json, top_k, apply_source_weights, pin_boost) {
|
|
2751
2993
|
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2752
2994
|
const len0 = WASM_VECTOR_LEN;
|
|
2753
2995
|
const ptr1 = passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
|
|
2754
2996
|
const len1 = WASM_VECTOR_LEN;
|
|
2755
2997
|
const ptr2 = passStringToWasm0(candidates_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2756
2998
|
const len2 = WASM_VECTOR_LEN;
|
|
2757
|
-
const ret = wasm.rerankWithConfig(ptr0, len0, ptr1, len1, ptr2, len2, top_k, apply_source_weights);
|
|
2999
|
+
const ret = wasm.rerankWithConfig(ptr0, len0, ptr1, len1, ptr2, len2, top_k, apply_source_weights, !isLikeNone(pin_boost), isLikeNone(pin_boost) ? 0 : pin_boost);
|
|
2758
3000
|
if (ret[2]) {
|
|
2759
3001
|
throw takeFromExternrefTable0(ret[1]);
|
|
2760
3002
|
}
|
|
Binary file
|